VirtualBox

Changeset 31781 in vbox for trunk/src/VBox/GuestHost/OpenGL


Ignore:
Timestamp:
Aug 19, 2010 11:14:24 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64968
Message:

crOpenGL: tabs to spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c

    r28860 r31781  
    2222void crStateTextureDestroy(CRContext *ctx)
    2323{
    24         crStateDeleteTextureObjectData(&ctx->texture.base1D);
    25         crStateDeleteTextureObjectData(&ctx->texture.proxy1D);
    26         crStateDeleteTextureObjectData(&ctx->texture.base2D);
    27         crStateDeleteTextureObjectData(&ctx->texture.proxy2D);
     24    crStateDeleteTextureObjectData(&ctx->texture.base1D);
     25    crStateDeleteTextureObjectData(&ctx->texture.proxy1D);
     26    crStateDeleteTextureObjectData(&ctx->texture.base2D);
     27    crStateDeleteTextureObjectData(&ctx->texture.proxy2D);
    2828#ifdef CR_OPENGL_VERSION_1_2
    29         crStateDeleteTextureObjectData(&ctx->texture.base3D);
    30         crStateDeleteTextureObjectData(&ctx->texture.proxy3D);
     29    crStateDeleteTextureObjectData(&ctx->texture.base3D);
     30    crStateDeleteTextureObjectData(&ctx->texture.proxy3D);
    3131#endif
    3232#ifdef CR_ARB_texture_cube_map
    33         crStateDeleteTextureObjectData(&ctx->texture.baseCubeMap);
    34         crStateDeleteTextureObjectData(&ctx->texture.proxyCubeMap);
     33    crStateDeleteTextureObjectData(&ctx->texture.baseCubeMap);
     34    crStateDeleteTextureObjectData(&ctx->texture.proxyCubeMap);
    3535#endif
    3636#ifdef CR_NV_texture_rectangle
    37         crStateDeleteTextureObjectData(&ctx->texture.baseRect);
    38         crStateDeleteTextureObjectData(&ctx->texture.proxyRect);
     37    crStateDeleteTextureObjectData(&ctx->texture.baseRect);
     38    crStateDeleteTextureObjectData(&ctx->texture.proxyRect);
    3939#endif
    4040}
     
    4343void crStateTextureInit(CRContext *ctx)
    4444{
    45         CRLimitsState *limits = &ctx->limits;
    46         CRTextureState *t = &ctx->texture;
    47         CRStateBits *sb = GetCurrentBits();
    48         CRTextureBits *tb = &(sb->texture);
    49         unsigned int i;
    50         unsigned int a;
    51         GLvectorf zero_vector = {0.0f, 0.0f, 0.0f, 0.0f};
    52         GLcolorf zero_color = {0.0f, 0.0f, 0.0f, 0.0f};
    53         GLvectorf x_vector = {1.0f, 0.0f, 0.0f, 0.0f};
    54         GLvectorf y_vector = {0.0f, 1.0f, 0.0f, 0.0f};
    55 
    56         /* compute max levels from max sizes */
    57         for (i=0, a=limits->maxTextureSize; a; i++, a=a>>1);
    58         t->maxLevel = i;
    59         for (i=0, a=limits->max3DTextureSize; a; i++, a=a>>1);
    60         t->max3DLevel = i;
     45    CRLimitsState *limits = &ctx->limits;
     46    CRTextureState *t = &ctx->texture;
     47    CRStateBits *sb = GetCurrentBits();
     48    CRTextureBits *tb = &(sb->texture);
     49    unsigned int i;
     50    unsigned int a;
     51    GLvectorf zero_vector = {0.0f, 0.0f, 0.0f, 0.0f};
     52    GLcolorf zero_color = {0.0f, 0.0f, 0.0f, 0.0f};
     53    GLvectorf x_vector = {1.0f, 0.0f, 0.0f, 0.0f};
     54    GLvectorf y_vector = {0.0f, 1.0f, 0.0f, 0.0f};
     55
     56    /* compute max levels from max sizes */
     57    for (i=0, a=limits->maxTextureSize; a; i++, a=a>>1);
     58    t->maxLevel = i;
     59    for (i=0, a=limits->max3DTextureSize; a; i++, a=a>>1);
     60    t->max3DLevel = i;
    6161#ifdef CR_ARB_texture_cube_map
    62         for (i=0, a=limits->maxCubeMapTextureSize; a; i++, a=a>>1);
    63         t->maxCubeMapLevel = i;
     62    for (i=0, a=limits->maxCubeMapTextureSize; a; i++, a=a>>1);
     63    t->maxCubeMapLevel = i;
    6464#endif
    6565#ifdef CR_NV_texture_rectangle
    66         for (i=0, a=limits->maxRectTextureSize; a; i++, a=a>>1);
    67         t->maxRectLevel = i;
    68 #endif
    69 
    70         crStateTextureInitTextureObj(ctx, &(t->base1D), 0, GL_TEXTURE_1D);
    71         crStateTextureInitTextureObj(ctx, &(t->base2D), 0, GL_TEXTURE_2D);
     66    for (i=0, a=limits->maxRectTextureSize; a; i++, a=a>>1);
     67    t->maxRectLevel = i;
     68#endif
     69
     70    crStateTextureInitTextureObj(ctx, &(t->base1D), 0, GL_TEXTURE_1D);
     71    crStateTextureInitTextureObj(ctx, &(t->base2D), 0, GL_TEXTURE_2D);
    7272#ifdef CR_OPENGL_VERSION_1_2
    73         crStateTextureInitTextureObj(ctx, &(t->base3D), 0, GL_TEXTURE_3D);
     73    crStateTextureInitTextureObj(ctx, &(t->base3D), 0, GL_TEXTURE_3D);
    7474#endif
    7575#ifdef CR_ARB_texture_cube_map
    76         crStateTextureInitTextureObj(ctx, &(t->baseCubeMap), 0,
    77                 GL_TEXTURE_CUBE_MAP_ARB);
     76    crStateTextureInitTextureObj(ctx, &(t->baseCubeMap), 0,
     77        GL_TEXTURE_CUBE_MAP_ARB);
    7878#endif
    7979#ifdef CR_NV_texture_rectangle
    80         crStateTextureInitTextureObj(ctx, &(t->baseRect), 0,
    81                 GL_TEXTURE_RECTANGLE_NV);
    82 #endif
    83 
    84         crStateTextureInitTextureObj(ctx, &(t->proxy1D), 0, GL_TEXTURE_1D);
    85         crStateTextureInitTextureObj(ctx, &(t->proxy2D), 0, GL_TEXTURE_2D);
     80    crStateTextureInitTextureObj(ctx, &(t->baseRect), 0,
     81        GL_TEXTURE_RECTANGLE_NV);
     82#endif
     83
     84    crStateTextureInitTextureObj(ctx, &(t->proxy1D), 0, GL_TEXTURE_1D);
     85    crStateTextureInitTextureObj(ctx, &(t->proxy2D), 0, GL_TEXTURE_2D);
    8686#ifdef CR_OPENGL_VERSION_1_2
    87         crStateTextureInitTextureObj(ctx, &(t->proxy3D), 0, GL_TEXTURE_3D);
     87    crStateTextureInitTextureObj(ctx, &(t->proxy3D), 0, GL_TEXTURE_3D);
    8888#endif
    8989#ifdef CR_ARB_texture_cube_map
    90         crStateTextureInitTextureObj(ctx, &(t->proxyCubeMap), 0,
    91                 GL_TEXTURE_CUBE_MAP_ARB);
     90    crStateTextureInitTextureObj(ctx, &(t->proxyCubeMap), 0,
     91        GL_TEXTURE_CUBE_MAP_ARB);
    9292#endif
    9393#ifdef CR_NV_texture_rectangle
    94         crStateTextureInitTextureObj(ctx, &(t->proxyRect), 0,
    95                 GL_TEXTURE_RECTANGLE_NV);
    96 #endif
    97 
    98         t->curTextureUnit = 0;
    99 
    100         /* Per-unit initialization */
    101         for (i = 0; i < limits->maxTextureUnits; i++)
    102         {
    103                 t->unit[i].currentTexture1D = &(t->base1D);
    104                 t->unit[i].currentTexture2D = &(t->base2D);
    105                 t->unit[i].currentTexture3D = &(t->base3D);
     94    crStateTextureInitTextureObj(ctx, &(t->proxyRect), 0,
     95        GL_TEXTURE_RECTANGLE_NV);
     96#endif
     97
     98    t->curTextureUnit = 0;
     99
     100    /* Per-unit initialization */
     101    for (i = 0; i < limits->maxTextureUnits; i++)
     102    {
     103        t->unit[i].currentTexture1D = &(t->base1D);
     104        t->unit[i].currentTexture2D = &(t->base2D);
     105        t->unit[i].currentTexture3D = &(t->base3D);
    106106#ifdef CR_ARB_texture_cube_map
    107                 t->unit[i].currentTextureCubeMap = &(t->baseCubeMap);
     107        t->unit[i].currentTextureCubeMap = &(t->baseCubeMap);
    108108#endif
    109109#ifdef CR_NV_texture_rectangle
    110                 t->unit[i].currentTextureRect = &(t->baseRect);
    111 #endif
    112 
    113                 t->unit[i].enabled1D = GL_FALSE;
    114                 t->unit[i].enabled2D = GL_FALSE;
    115                 t->unit[i].enabled3D = GL_FALSE;
    116                 t->unit[i].enabledCubeMap = GL_FALSE;
     110        t->unit[i].currentTextureRect = &(t->baseRect);
     111#endif
     112
     113        t->unit[i].enabled1D = GL_FALSE;
     114        t->unit[i].enabled2D = GL_FALSE;
     115        t->unit[i].enabled3D = GL_FALSE;
     116        t->unit[i].enabledCubeMap = GL_FALSE;
    117117#ifdef CR_NV_texture_rectangle
    118                 t->unit[i].enabledRect = GL_FALSE;
    119 #endif
    120                 t->unit[i].textureGen.s = GL_FALSE;
    121                 t->unit[i].textureGen.t = GL_FALSE;
    122                 t->unit[i].textureGen.r = GL_FALSE;
    123                 t->unit[i].textureGen.q = GL_FALSE;
    124 
    125                 t->unit[i].gen.s = GL_EYE_LINEAR;
    126                 t->unit[i].gen.t = GL_EYE_LINEAR;
    127                 t->unit[i].gen.r = GL_EYE_LINEAR;
    128                 t->unit[i].gen.q = GL_EYE_LINEAR;
    129 
    130                 t->unit[i].objSCoeff = x_vector;
    131                 t->unit[i].objTCoeff = y_vector;
    132                 t->unit[i].objRCoeff = zero_vector;
    133                 t->unit[i].objQCoeff = zero_vector;
    134 
    135                 t->unit[i].eyeSCoeff = x_vector;
    136                 t->unit[i].eyeTCoeff = y_vector;
    137                 t->unit[i].eyeRCoeff = zero_vector;
    138                 t->unit[i].eyeQCoeff = zero_vector;
    139                 t->unit[i].envMode = GL_MODULATE;
    140                 t->unit[i].envColor = zero_color;
    141 
    142                 t->unit[i].combineModeRGB = GL_MODULATE;
    143                 t->unit[i].combineModeA = GL_MODULATE;
    144                 t->unit[i].combineSourceRGB[0] = GL_TEXTURE;
    145                 t->unit[i].combineSourceRGB[1] = GL_PREVIOUS_EXT;
    146                 t->unit[i].combineSourceRGB[2] = GL_CONSTANT_EXT;
    147                 t->unit[i].combineSourceA[0] = GL_TEXTURE;
    148                 t->unit[i].combineSourceA[1] = GL_PREVIOUS_EXT;
    149                 t->unit[i].combineSourceA[2] = GL_CONSTANT_EXT;
    150                 t->unit[i].combineOperandRGB[0] = GL_SRC_COLOR;
    151                 t->unit[i].combineOperandRGB[1] = GL_SRC_COLOR;
    152                 t->unit[i].combineOperandRGB[2] = GL_SRC_ALPHA;
    153                 t->unit[i].combineOperandA[0] = GL_SRC_ALPHA;
    154                 t->unit[i].combineOperandA[1] = GL_SRC_ALPHA;
    155                 t->unit[i].combineOperandA[2] = GL_SRC_ALPHA;
    156                 t->unit[i].combineScaleRGB = 1.0F;
    157                 t->unit[i].combineScaleA = 1.0F;
     118        t->unit[i].enabledRect = GL_FALSE;
     119#endif
     120        t->unit[i].textureGen.s = GL_FALSE;
     121        t->unit[i].textureGen.t = GL_FALSE;
     122        t->unit[i].textureGen.r = GL_FALSE;
     123        t->unit[i].textureGen.q = GL_FALSE;
     124
     125        t->unit[i].gen.s = GL_EYE_LINEAR;
     126        t->unit[i].gen.t = GL_EYE_LINEAR;
     127        t->unit[i].gen.r = GL_EYE_LINEAR;
     128        t->unit[i].gen.q = GL_EYE_LINEAR;
     129
     130        t->unit[i].objSCoeff = x_vector;
     131        t->unit[i].objTCoeff = y_vector;
     132        t->unit[i].objRCoeff = zero_vector;
     133        t->unit[i].objQCoeff = zero_vector;
     134
     135        t->unit[i].eyeSCoeff = x_vector;
     136        t->unit[i].eyeTCoeff = y_vector;
     137        t->unit[i].eyeRCoeff = zero_vector;
     138        t->unit[i].eyeQCoeff = zero_vector;
     139        t->unit[i].envMode = GL_MODULATE;
     140        t->unit[i].envColor = zero_color;
     141
     142        t->unit[i].combineModeRGB = GL_MODULATE;
     143        t->unit[i].combineModeA = GL_MODULATE;
     144        t->unit[i].combineSourceRGB[0] = GL_TEXTURE;
     145        t->unit[i].combineSourceRGB[1] = GL_PREVIOUS_EXT;
     146        t->unit[i].combineSourceRGB[2] = GL_CONSTANT_EXT;
     147        t->unit[i].combineSourceA[0] = GL_TEXTURE;
     148        t->unit[i].combineSourceA[1] = GL_PREVIOUS_EXT;
     149        t->unit[i].combineSourceA[2] = GL_CONSTANT_EXT;
     150        t->unit[i].combineOperandRGB[0] = GL_SRC_COLOR;
     151        t->unit[i].combineOperandRGB[1] = GL_SRC_COLOR;
     152        t->unit[i].combineOperandRGB[2] = GL_SRC_ALPHA;
     153        t->unit[i].combineOperandA[0] = GL_SRC_ALPHA;
     154        t->unit[i].combineOperandA[1] = GL_SRC_ALPHA;
     155        t->unit[i].combineOperandA[2] = GL_SRC_ALPHA;
     156        t->unit[i].combineScaleRGB = 1.0F;
     157        t->unit[i].combineScaleA = 1.0F;
    158158#ifdef CR_EXT_texture_lod_bias
    159                 t->unit[i].lodBias = 0.0F;
    160 #endif
    161                 RESET(tb->enable[i], ctx->bitid);
    162                 RESET(tb->current[i], ctx->bitid);
    163                 RESET(tb->objGen[i], ctx->bitid);
    164                 RESET(tb->eyeGen[i], ctx->bitid);
    165                 RESET(tb->genMode[i], ctx->bitid);
    166                 RESET(tb->envBit[i], ctx->bitid);
    167         }
    168         RESET(tb->dirty, ctx->bitid);
     159        t->unit[i].lodBias = 0.0F;
     160#endif
     161        RESET(tb->enable[i], ctx->bitid);
     162        RESET(tb->current[i], ctx->bitid);
     163        RESET(tb->objGen[i], ctx->bitid);
     164        RESET(tb->eyeGen[i], ctx->bitid);
     165        RESET(tb->genMode[i], ctx->bitid);
     166        RESET(tb->envBit[i], ctx->bitid);
     167    }
     168    RESET(tb->dirty, ctx->bitid);
    169169}
    170170
     
    172172void
    173173crStateTextureInitTextureObj(CRContext *ctx, CRTextureObj *tobj,
    174                                                                                                                 GLuint name, GLenum target)
    175 {
    176         const CRTextureState *t = &(ctx->texture);
    177         int i, face;
    178 
    179         tobj->borderColor.r = 0.0f;
    180         tobj->borderColor.g = 0.0f;
    181         tobj->borderColor.b = 0.0f;
    182         tobj->borderColor.a = 0.0f;
    183         tobj->minFilter     = GL_NEAREST_MIPMAP_LINEAR;
    184         tobj->magFilter     = GL_LINEAR;
    185         tobj->wrapS         = GL_REPEAT;
    186         tobj->wrapT         = GL_REPEAT;
     174                                                        GLuint name, GLenum target)
     175{
     176    const CRTextureState *t = &(ctx->texture);
     177    int i, face;
     178
     179    tobj->borderColor.r = 0.0f;
     180    tobj->borderColor.g = 0.0f;
     181    tobj->borderColor.b = 0.0f;
     182    tobj->borderColor.a = 0.0f;
     183    tobj->minFilter     = GL_NEAREST_MIPMAP_LINEAR;
     184    tobj->magFilter     = GL_LINEAR;
     185    tobj->wrapS         = GL_REPEAT;
     186    tobj->wrapT         = GL_REPEAT;
    187187#ifdef CR_OPENGL_VERSION_1_2
    188         tobj->wrapR         = GL_REPEAT;
    189         tobj->priority      = 1.0f;
    190         tobj->minLod        = -1000.0;
    191         tobj->maxLod        = 1000.0;
    192         tobj->baseLevel     = 0;
    193         tobj->maxLevel      = 1000;
    194 #endif
    195         tobj->target        = target;
    196         tobj->name          = name;
    197 
    198         CRASSERT(t->maxLevel);
    199 
    200         /* XXX don't always need all six faces */
    201         for (face = 0; face < 6; face++) {
    202                 /* allocate array of mipmap levels */
    203                 CRASSERT(t->maxLevel < CR_MAX_MIPMAP_LEVELS);
    204                 tobj->level[face] = (CRTextureLevel *)
    205                         crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS);
    206 
    207                 if (!tobj->level[face])
    208                         return; /* out of memory */
    209 
    210                 /* init non-zero fields */
    211                 for (i = 0; i <= t->maxLevel; i++) {
    212                         CRTextureLevel *tl = &(tobj->level[face][i]);
    213                         tl->internalFormat = GL_ONE;
    214                         tl->format = GL_RGBA;
    215                         tl->type = GL_UNSIGNED_BYTE;
    216                         crStateTextureInitTextureFormat( tl, tl->internalFormat );
    217                 }
    218         }
     188    tobj->wrapR         = GL_REPEAT;
     189    tobj->priority      = 1.0f;
     190    tobj->minLod        = -1000.0;
     191    tobj->maxLod        = 1000.0;
     192    tobj->baseLevel     = 0;
     193    tobj->maxLevel      = 1000;
     194#endif
     195    tobj->target        = target;
     196    tobj->name          = name;
     197
     198    CRASSERT(t->maxLevel);
     199
     200    /* XXX don't always need all six faces */
     201    for (face = 0; face < 6; face++) {
     202        /* allocate array of mipmap levels */
     203        CRASSERT(t->maxLevel < CR_MAX_MIPMAP_LEVELS);
     204        tobj->level[face] = (CRTextureLevel *)
     205            crCalloc(sizeof(CRTextureLevel) * CR_MAX_MIPMAP_LEVELS);
     206
     207        if (!tobj->level[face])
     208            return; /* out of memory */
     209
     210        /* init non-zero fields */
     211        for (i = 0; i <= t->maxLevel; i++) {
     212            CRTextureLevel *tl = &(tobj->level[face][i]);
     213            tl->internalFormat = GL_ONE;
     214            tl->format = GL_RGBA;
     215            tl->type = GL_UNSIGNED_BYTE;
     216            crStateTextureInitTextureFormat( tl, tl->internalFormat );
     217        }
     218    }
    219219
    220220#ifdef CR_EXT_texture_filter_anisotropic
    221         tobj->maxAnisotropy = 1.0f;
     221    tobj->maxAnisotropy = 1.0f;
    222222#endif
    223223
    224224#ifdef CR_ARB_depth_texture
    225         tobj->depthMode = GL_LUMINANCE;
     225    tobj->depthMode = GL_LUMINANCE;
    226226#endif
    227227
    228228#ifdef CR_ARB_shadow
    229         tobj->compareMode = GL_NONE;
    230         tobj->compareFunc = GL_LEQUAL;
     229    tobj->compareMode = GL_NONE;
     230    tobj->compareFunc = GL_LEQUAL;
    231231#endif
    232232
    233233#ifdef CR_ARB_shadow_ambient
    234         tobj->compareFailValue = 0.0;
    235 #endif
    236 
    237         RESET(tobj->dirty, ctx->bitid);
    238         RESET(tobj->imageBit, ctx->bitid);
    239         for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++)
    240         {
    241                 RESET(tobj->paramsBit[i], ctx->bitid);
    242         }
     234    tobj->compareFailValue = 0.0;
     235#endif
     236
     237    RESET(tobj->dirty, ctx->bitid);
     238    RESET(tobj->imageBit, ctx->bitid);
     239    for (i = 0; i < CR_MAX_TEXTURE_UNITS; i++)
     240    {
     241        RESET(tobj->paramsBit[i], ctx->bitid);
     242    }
    243243}
    244244
     
    249249
    250250const CRTextureFormat _texformat_rgba8888 = {
    251    8,                           /* RedBits */
    252    8,                           /* GreenBits */
    253    8,                           /* BlueBits */
    254    8,                           /* AlphaBits */
    255    0,                           /* LuminanceBits */
    256    0,                           /* IntensityBits */
    257    0,                           /* IndexBits */
     251   8,               /* RedBits */
     252   8,               /* GreenBits */
     253   8,               /* BlueBits */
     254   8,               /* AlphaBits */
     255   0,               /* LuminanceBits */
     256   0,               /* IntensityBits */
     257   0,               /* IndexBits */
    258258};
    259259
    260260const CRTextureFormat _texformat_argb8888 = {
    261    8,                           /* RedBits */
    262    8,                           /* GreenBits */
    263    8,                           /* BlueBits */
    264    8,                           /* AlphaBits */
    265    0,                           /* LuminanceBits */
    266    0,                           /* IntensityBits */
    267    0,                           /* IndexBits */
     261   8,               /* RedBits */
     262   8,               /* GreenBits */
     263   8,               /* BlueBits */
     264   8,               /* AlphaBits */
     265   0,               /* LuminanceBits */
     266   0,               /* IntensityBits */
     267   0,               /* IndexBits */
    268268};
    269269
    270270const CRTextureFormat _texformat_rgb888 = {
    271    8,                           /* RedBits */
    272    8,                           /* GreenBits */
    273    8,                           /* BlueBits */
    274    0,                           /* AlphaBits */
    275    0,                           /* LuminanceBits */
    276    0,                           /* IntensityBits */
    277    0,                           /* IndexBits */
     271   8,               /* RedBits */
     272   8,               /* GreenBits */
     273   8,               /* BlueBits */
     274   0,               /* AlphaBits */
     275   0,               /* LuminanceBits */
     276   0,               /* IntensityBits */
     277   0,               /* IndexBits */
    278278};
    279279
    280280const CRTextureFormat _texformat_rgb565 = {
    281    5,                           /* RedBits */
    282    6,                           /* GreenBits */
    283    5,                           /* BlueBits */
    284    0,                           /* AlphaBits */
    285    0,                           /* LuminanceBits */
    286    0,                           /* IntensityBits */
    287    0,                           /* IndexBits */
     281   5,               /* RedBits */
     282   6,               /* GreenBits */
     283   5,               /* BlueBits */
     284   0,               /* AlphaBits */
     285   0,               /* LuminanceBits */
     286   0,               /* IntensityBits */
     287   0,               /* IndexBits */
    288288};
    289289
    290290const CRTextureFormat _texformat_argb4444 = {
    291    4,                           /* RedBits */
    292    4,                           /* GreenBits */
    293    4,                           /* BlueBits */
    294    4,                           /* AlphaBits */
    295    0,                           /* LuminanceBits */
    296    0,                           /* IntensityBits */
    297    0,                           /* IndexBits */
     291   4,               /* RedBits */
     292   4,               /* GreenBits */
     293   4,               /* BlueBits */
     294   4,               /* AlphaBits */
     295   0,               /* LuminanceBits */
     296   0,               /* IntensityBits */
     297   0,               /* IndexBits */
    298298};
    299299
    300300const CRTextureFormat _texformat_argb1555 = {
    301    5,                           /* RedBits */
    302    5,                           /* GreenBits */
    303    5,                           /* BlueBits */
    304    1,                           /* AlphaBits */
    305    0,                           /* LuminanceBits */
    306    0,                           /* IntensityBits */
    307    0,                           /* IndexBits */
     301   5,               /* RedBits */
     302   5,               /* GreenBits */
     303   5,               /* BlueBits */
     304   1,               /* AlphaBits */
     305   0,               /* LuminanceBits */
     306   0,               /* IntensityBits */
     307   0,               /* IndexBits */
    308308};
    309309
    310310const CRTextureFormat _texformat_al88 = {
    311    0,                           /* RedBits */
    312    0,                           /* GreenBits */
    313    0,                           /* BlueBits */
    314    8,                           /* AlphaBits */
    315    8,                           /* LuminanceBits */
    316    0,                           /* IntensityBits */
    317    0,                           /* IndexBits */
     311   0,               /* RedBits */
     312   0,               /* GreenBits */
     313   0,               /* BlueBits */
     314   8,               /* AlphaBits */
     315   8,               /* LuminanceBits */
     316   0,               /* IntensityBits */
     317   0,               /* IndexBits */
    318318};
    319319
    320320const CRTextureFormat _texformat_rgb332 = {
    321    3,                           /* RedBits */
    322    3,                           /* GreenBits */
    323    2,                           /* BlueBits */
    324    0,                           /* AlphaBits */
    325    0,                           /* LuminanceBits */
    326    0,                           /* IntensityBits */
    327    0,                           /* IndexBits */
     321   3,               /* RedBits */
     322   3,               /* GreenBits */
     323   2,               /* BlueBits */
     324   0,               /* AlphaBits */
     325   0,               /* LuminanceBits */
     326   0,               /* IntensityBits */
     327   0,               /* IndexBits */
    328328};
    329329
    330330const CRTextureFormat _texformat_a8 = {
    331    0,                           /* RedBits */
    332    0,                           /* GreenBits */
    333    0,                           /* BlueBits */
    334    8,                           /* AlphaBits */
    335    0,                           /* LuminanceBits */
    336    0,                           /* IntensityBits */
    337    0,                           /* IndexBits */
     331   0,               /* RedBits */
     332   0,               /* GreenBits */
     333   0,               /* BlueBits */
     334   8,               /* AlphaBits */
     335   0,               /* LuminanceBits */
     336   0,               /* IntensityBits */
     337   0,               /* IndexBits */
    338338};
    339339
    340340const CRTextureFormat _texformat_l8 = {
    341    0,                           /* RedBits */
    342    0,                           /* GreenBits */
    343    0,                           /* BlueBits */
    344    0,                           /* AlphaBits */
    345    8,                           /* LuminanceBits */
    346    0,                           /* IntensityBits */
    347    0,                           /* IndexBits */
     341   0,               /* RedBits */
     342   0,               /* GreenBits */
     343   0,               /* BlueBits */
     344   0,               /* AlphaBits */
     345   8,               /* LuminanceBits */
     346   0,               /* IntensityBits */
     347   0,               /* IndexBits */
    348348};
    349349
    350350const CRTextureFormat _texformat_i8 = {
    351    0,                           /* RedBits */
    352    0,                           /* GreenBits */
    353    0,                           /* BlueBits */
    354    0,                           /* AlphaBits */
    355    0,                           /* LuminanceBits */
    356    8,                           /* IntensityBits */
    357    0,                           /* IndexBits */
     351   0,               /* RedBits */
     352   0,               /* GreenBits */
     353   0,               /* BlueBits */
     354   0,               /* AlphaBits */
     355   0,               /* LuminanceBits */
     356   8,               /* IntensityBits */
     357   0,               /* IndexBits */
    358358};
    359359
    360360const CRTextureFormat _texformat_ci8 = {
    361    0,                           /* RedBits */
    362    0,                           /* GreenBits */
    363    0,                           /* BlueBits */
    364    0,                           /* AlphaBits */
    365    0,                           /* LuminanceBits */
    366    0,                           /* IntensityBits */
    367    8,                           /* IndexBits */
     361   0,               /* RedBits */
     362   0,               /* GreenBits */
     363   0,               /* BlueBits */
     364   0,               /* AlphaBits */
     365   0,               /* LuminanceBits */
     366   0,               /* IntensityBits */
     367   8,               /* IndexBits */
    368368};
    369369
     
    378378crStateTextureInitTextureFormat( CRTextureLevel *tl, GLenum internalFormat )
    379379{
    380         switch (internalFormat) {
    381         case 4:
    382         case GL_RGBA:
    383         case GL_COMPRESSED_RGBA_ARB:
     380    switch (internalFormat) {
     381    case 4:
     382    case GL_RGBA:
     383    case GL_COMPRESSED_RGBA_ARB:
    384384#ifdef CR_EXT_texture_sRGB
    385385    case GL_SRGB_ALPHA_EXT:
     
    387387    case GL_COMPRESSED_SRGB_ALPHA_EXT:
    388388#endif
    389                 tl->texFormat = &_texformat_rgba8888;
    390                 break;
    391 
    392         case 3:
    393         case GL_RGB:
    394         case GL_COMPRESSED_RGB_ARB:
     389        tl->texFormat = &_texformat_rgba8888;
     390        break;
     391
     392    case 3:
     393    case GL_RGB:
     394    case GL_COMPRESSED_RGB_ARB:
    395395#ifdef CR_EXT_texture_sRGB
    396396    case GL_SRGB_EXT:
     
    398398    case GL_COMPRESSED_SRGB_EXT:
    399399#endif
    400                 tl->texFormat = &_texformat_rgb888;
    401                 break;
    402 
    403         case GL_RGBA2:
    404         case GL_RGBA4:
    405         case GL_RGB5_A1:
    406         case GL_RGBA8:
    407         case GL_RGB10_A2:
    408         case GL_RGBA12:
    409         case GL_RGBA16:
    410                 tl->texFormat = &_texformat_rgba8888;
    411                 break;
    412 
    413         case GL_R3_G3_B2:
    414                 tl->texFormat = &_texformat_rgb332;
    415                 break;
    416         case GL_RGB4:
    417         case GL_RGB5:
    418         case GL_RGB8:
    419         case GL_RGB10:
    420         case GL_RGB12:
    421         case GL_RGB16:
    422                 tl->texFormat = &_texformat_rgb888;
    423                 break;
    424 
    425         case GL_ALPHA:
    426         case GL_ALPHA4:
    427         case GL_ALPHA8:
    428         case GL_ALPHA12:
    429         case GL_ALPHA16:
    430         case GL_COMPRESSED_ALPHA_ARB:
    431                 tl->texFormat = &_texformat_a8;
    432                 break;
    433 
    434         case 1:
    435         case GL_LUMINANCE:
    436         case GL_LUMINANCE4:
    437         case GL_LUMINANCE8:
    438         case GL_LUMINANCE12:
    439         case GL_LUMINANCE16:
    440         case GL_COMPRESSED_LUMINANCE_ARB:
     400        tl->texFormat = &_texformat_rgb888;
     401        break;
     402
     403    case GL_RGBA2:
     404    case GL_RGBA4:
     405    case GL_RGB5_A1:
     406    case GL_RGBA8:
     407    case GL_RGB10_A2:
     408    case GL_RGBA12:
     409    case GL_RGBA16:
     410        tl->texFormat = &_texformat_rgba8888;
     411        break;
     412
     413    case GL_R3_G3_B2:
     414        tl->texFormat = &_texformat_rgb332;
     415        break;
     416    case GL_RGB4:
     417    case GL_RGB5:
     418    case GL_RGB8:
     419    case GL_RGB10:
     420    case GL_RGB12:
     421    case GL_RGB16:
     422        tl->texFormat = &_texformat_rgb888;
     423        break;
     424
     425    case GL_ALPHA:
     426    case GL_ALPHA4:
     427    case GL_ALPHA8:
     428    case GL_ALPHA12:
     429    case GL_ALPHA16:
     430    case GL_COMPRESSED_ALPHA_ARB:
     431        tl->texFormat = &_texformat_a8;
     432        break;
     433
     434    case 1:
     435    case GL_LUMINANCE:
     436    case GL_LUMINANCE4:
     437    case GL_LUMINANCE8:
     438    case GL_LUMINANCE12:
     439    case GL_LUMINANCE16:
     440    case GL_COMPRESSED_LUMINANCE_ARB:
    441441#ifdef CR_EXT_texture_sRGB
    442442    case GL_SLUMINANCE_EXT:
     
    444444    case GL_COMPRESSED_SLUMINANCE_EXT:
    445445#endif
    446                 tl->texFormat = &_texformat_l8;
    447                 break;
    448 
    449         case 2:
    450         case GL_LUMINANCE_ALPHA:
    451         case GL_LUMINANCE4_ALPHA4:
    452         case GL_LUMINANCE6_ALPHA2:
    453         case GL_LUMINANCE8_ALPHA8:
    454         case GL_LUMINANCE12_ALPHA4:
    455         case GL_LUMINANCE12_ALPHA12:
    456         case GL_LUMINANCE16_ALPHA16:
    457         case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
     446        tl->texFormat = &_texformat_l8;
     447        break;
     448
     449    case 2:
     450    case GL_LUMINANCE_ALPHA:
     451    case GL_LUMINANCE4_ALPHA4:
     452    case GL_LUMINANCE6_ALPHA2:
     453    case GL_LUMINANCE8_ALPHA8:
     454    case GL_LUMINANCE12_ALPHA4:
     455    case GL_LUMINANCE12_ALPHA12:
     456    case GL_LUMINANCE16_ALPHA16:
     457    case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
    458458#ifdef CR_EXT_texture_sRGB
    459459    case GL_SLUMINANCE_ALPHA_EXT:
     
    461461    case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
    462462#endif
    463                 tl->texFormat = &_texformat_al88;
    464                 break;
    465 
    466         case GL_INTENSITY:
    467         case GL_INTENSITY4:
    468         case GL_INTENSITY8:
    469         case GL_INTENSITY12:
    470         case GL_INTENSITY16:
    471         case GL_COMPRESSED_INTENSITY_ARB:
    472                 tl->texFormat = &_texformat_i8;
    473                 break;
    474 
    475         case GL_COLOR_INDEX:
    476         case GL_COLOR_INDEX1_EXT:
    477         case GL_COLOR_INDEX2_EXT:
    478         case GL_COLOR_INDEX4_EXT:
    479         case GL_COLOR_INDEX8_EXT:
    480         case GL_COLOR_INDEX12_EXT:
    481         case GL_COLOR_INDEX16_EXT:
    482                 tl->texFormat = &_texformat_ci8;
    483                 break;
    484 
    485         default:
    486                 return;
    487         }
     463        tl->texFormat = &_texformat_al88;
     464        break;
     465
     466    case GL_INTENSITY:
     467    case GL_INTENSITY4:
     468    case GL_INTENSITY8:
     469    case GL_INTENSITY12:
     470    case GL_INTENSITY16:
     471    case GL_COMPRESSED_INTENSITY_ARB:
     472        tl->texFormat = &_texformat_i8;
     473        break;
     474
     475    case GL_COLOR_INDEX:
     476    case GL_COLOR_INDEX1_EXT:
     477    case GL_COLOR_INDEX2_EXT:
     478    case GL_COLOR_INDEX4_EXT:
     479    case GL_COLOR_INDEX8_EXT:
     480    case GL_COLOR_INDEX12_EXT:
     481    case GL_COLOR_INDEX16_EXT:
     482        tl->texFormat = &_texformat_ci8;
     483        break;
     484
     485    default:
     486        return;
     487    }
    488488}
    489489
     
    491491void crStateTextureInitTexture (GLuint name)
    492492{
    493         CRContext *g = GetCurrentContext();
    494         CRTextureState *t = &(g->texture);
    495         CRTextureObj *tobj;
    496 
    497         GET_TOBJ(tobj, name);
    498         if (!tobj) return;
    499 
    500         crStateTextureInitTextureObj(g, tobj, name, GL_NONE);
     493    CRContext *g = GetCurrentContext();
     494    CRTextureState *t = &(g->texture);
     495    CRTextureObj *tobj;
     496
     497    GET_TOBJ(tobj, name);
     498    if (!tobj) return;
     499
     500    crStateTextureInitTextureObj(g, tobj, name, GL_NONE);
    501501}
    502502#endif
     
    510510crStateTextureGet(GLenum target, GLuint name)
    511511{
    512         CRContext *g = GetCurrentContext();
    513         CRTextureState *t = &(g->texture);
    514         CRTextureObj *tobj;
    515 
    516         if (name == 0)
    517         {
    518                 switch (target) {
    519                 case GL_TEXTURE_1D:
    520                         return &t->base1D;
    521                 case GL_TEXTURE_2D:
    522                         return &t->base2D;
    523                 case GL_TEXTURE_3D:
    524                         return &t->base3D;
     512    CRContext *g = GetCurrentContext();
     513    CRTextureState *t = &(g->texture);
     514    CRTextureObj *tobj;
     515
     516    if (name == 0)
     517    {
     518        switch (target) {
     519        case GL_TEXTURE_1D:
     520            return &t->base1D;
     521        case GL_TEXTURE_2D:
     522            return &t->base2D;
     523        case GL_TEXTURE_3D:
     524            return &t->base3D;
    525525#ifdef CR_ARB_texture_cube_map
    526                 case GL_TEXTURE_CUBE_MAP_ARB:
    527                         return &t->baseCubeMap;
     526        case GL_TEXTURE_CUBE_MAP_ARB:
     527            return &t->baseCubeMap;
    528528#endif
    529529#ifdef CR_NV_texture_rectangle
    530                 case GL_TEXTURE_RECTANGLE_NV:
    531                         return &t->baseRect;
    532 #endif
    533                 default:
    534                         return NULL;
    535                 }
    536         }
    537 
    538         GET_TOBJ(tobj, g, name);
    539 
    540         return tobj;
     530        case GL_TEXTURE_RECTANGLE_NV:
     531            return &t->baseRect;
     532#endif
     533        default:
     534            return NULL;
     535        }
     536    }
     537
     538    GET_TOBJ(tobj, g, name);
     539
     540    return tobj;
    541541}
    542542
     
    549549crStateTextureAllocate_t(CRContext *ctx, GLuint name)
    550550{
    551         CRTextureObj *tobj;
    552 
    553         if (!name)
    554                 return NULL;
    555 
    556         tobj = crCalloc(sizeof(CRTextureObj));
    557         if (!tobj)
    558                 return NULL;
    559 
    560         crHashtableAdd( ctx->shared->textureTable, name, (void *) tobj );
    561 
    562         crStateTextureInitTextureObj(ctx, tobj, name, GL_NONE);
    563 
    564         return tobj;
     551    CRTextureObj *tobj;
     552
     553    if (!name)
     554        return NULL;
     555
     556    tobj = crCalloc(sizeof(CRTextureObj));
     557    if (!tobj)
     558        return NULL;
     559
     560    crHashtableAdd( ctx->shared->textureTable, name, (void *) tobj );
     561
     562    crStateTextureInitTextureObj(ctx, tobj, name, GL_NONE);
     563
     564    return tobj;
    565565}
    566566
     
    574574crStateDeleteTextureObjectData(CRTextureObj *tobj)
    575575{
    576         int k;
    577         int face;
    578 
    579         CRASSERT(tobj);
    580 
    581         /* Free the texture images */
    582         for (face = 0; face < 6; face++) {
    583                 CRTextureLevel *levels = NULL;
    584                 levels = tobj->level[face];
    585                 if (levels) {
    586                         /* free all mipmap levels for this face */
    587                         for (k = 0; k < CR_MAX_MIPMAP_LEVELS; k++) {
    588                                 CRTextureLevel *tl = levels + k;
    589                                 if (tl->img) {
    590                                         crFree(tl->img);
    591                                         tl->img = NULL;
    592                                         tl->bytes = 0;
    593                                 }
    594                         }
    595                         crFree(levels);
    596                 }
    597                 tobj->level[face] = NULL;
    598         }
     576    int k;
     577    int face;
     578
     579    CRASSERT(tobj);
     580
     581    /* Free the texture images */
     582    for (face = 0; face < 6; face++) {
     583        CRTextureLevel *levels = NULL;
     584        levels = tobj->level[face];
     585        if (levels) {
     586            /* free all mipmap levels for this face */
     587            for (k = 0; k < CR_MAX_MIPMAP_LEVELS; k++) {
     588                CRTextureLevel *tl = levels + k;
     589                if (tl->img) {
     590                    crFree(tl->img);
     591                    tl->img = NULL;
     592                    tl->bytes = 0;
     593                }
     594            }
     595            crFree(levels);
     596        }
     597        tobj->level[face] = NULL;
     598    }
    599599}
    600600
     
    603603crStateDeleteTextureObject(CRTextureObj *tobj)
    604604{
    605         crStateDeleteTextureObjectData(tobj);
    606         crFree(tobj);
     605    crStateDeleteTextureObjectData(tobj);
     606    crFree(tobj);
    607607}
    608608
    609609void STATE_APIENTRY crStateGenTextures(GLsizei n, GLuint *textures)
    610610{
    611         CRContext *g = GetCurrentContext();
    612         GLint start;
    613 
    614         FLUSH();
    615 
    616         if (g->current.inBeginEnd)
    617         {
    618                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    619                                                                 "glGenTextures called in Begin/End");
    620                 return;
    621         }
    622 
    623         if (n < 0)
    624         {
    625                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    626                                                                 "Negative n passed to glGenTextures: %d", n);
    627                 return;
    628         }
    629 
    630         start = crHashtableAllocKeys(g->shared->textureTable, n);
    631         if (start)
    632         {
    633                 GLint i;
    634                 for (i = 0; i < n; i++)
    635                         textures[i] = (GLuint) (start + i);
    636         }
    637         else
    638         {
    639                 crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenTextures");
    640         }
     611    CRContext *g = GetCurrentContext();
     612    GLint start;
     613
     614    FLUSH();
     615
     616    if (g->current.inBeginEnd)
     617    {
     618        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     619                                "glGenTextures called in Begin/End");
     620        return;
     621    }
     622
     623    if (n < 0)
     624    {
     625        crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     626                                "Negative n passed to glGenTextures: %d", n);
     627        return;
     628    }
     629
     630    start = crHashtableAllocKeys(g->shared->textureTable, n);
     631    if (start)
     632    {
     633        GLint i;
     634        for (i = 0; i < n; i++)
     635            textures[i] = (GLuint) (start + i);
     636    }
     637    else
     638    {
     639        crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenTextures");
     640    }
    641641}
    642642
     
    676676void STATE_APIENTRY crStateDeleteTextures(GLsizei n, const GLuint *textures)
    677677{
    678         CRContext *g = GetCurrentContext();
    679         CRTextureState *t = &(g->texture);
    680         CRStateBits *sb = GetCurrentBits();
    681         CRTextureBits *tb = &(sb->texture);
    682         int i;
    683 
    684         FLUSH();
    685 
    686         if (g->current.inBeginEnd)
    687         {
    688                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    689                                                                 "glDeleteTextures called in Begin/End");
    690                 return;
    691         }
    692 
    693         if (n < 0)
    694         {
    695                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    696                                                                 "Negative n passed to glDeleteTextures: %d", n);
    697                 return;
    698         }
    699 
    700         for (i=0; i<n; i++)
    701         {
    702                 GLuint name = textures[i];
    703                 CRTextureObj *tObj;
    704                 GET_TOBJ(tObj, g, name);
    705                 if (name && tObj)
    706                 {
    707                         GLuint u;
    708                         /* remove from hashtable */
    709                         crHashtableDelete(g->shared->textureTable, name, NULL);
    710 
    711                         /* if the currentTexture is deleted,
    712                         ** reset back to the base texture.
    713                         */
    714                         for (u = 0; u < g->limits.maxTextureUnits; u++)
    715                         {
    716                                 if (tObj == t->unit[u].currentTexture1D)
    717                                 {
    718                                         t->unit[u].currentTexture1D = &(t->base1D);
    719                                 }
    720                                 if (tObj == t->unit[u].currentTexture2D)
    721                                 {
    722                                         t->unit[u].currentTexture2D = &(t->base2D);
    723                                 }
     678    CRContext *g = GetCurrentContext();
     679    CRTextureState *t = &(g->texture);
     680    CRStateBits *sb = GetCurrentBits();
     681    CRTextureBits *tb = &(sb->texture);
     682    int i;
     683
     684    FLUSH();
     685
     686    if (g->current.inBeginEnd)
     687    {
     688        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     689                                "glDeleteTextures called in Begin/End");
     690        return;
     691    }
     692
     693    if (n < 0)
     694    {
     695        crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     696                                "Negative n passed to glDeleteTextures: %d", n);
     697        return;
     698    }
     699
     700    for (i=0; i<n; i++)
     701    {
     702        GLuint name = textures[i];
     703        CRTextureObj *tObj;
     704        GET_TOBJ(tObj, g, name);
     705        if (name && tObj)
     706        {
     707            GLuint u;
     708            /* remove from hashtable */
     709            crHashtableDelete(g->shared->textureTable, name, NULL);
     710
     711            /* if the currentTexture is deleted,
     712            ** reset back to the base texture.
     713            */
     714            for (u = 0; u < g->limits.maxTextureUnits; u++)
     715            {
     716                if (tObj == t->unit[u].currentTexture1D)
     717                {
     718                    t->unit[u].currentTexture1D = &(t->base1D);
     719                }
     720                if (tObj == t->unit[u].currentTexture2D)
     721                {
     722                    t->unit[u].currentTexture2D = &(t->base2D);
     723                }
    724724#ifdef CR_OPENGL_VERSION_1_2
    725                                 if (tObj == t->unit[u].currentTexture3D)
    726                                 {
    727                                         t->unit[u].currentTexture3D = &(t->base3D);
    728                                 }
     725                if (tObj == t->unit[u].currentTexture3D)
     726                {
     727                    t->unit[u].currentTexture3D = &(t->base3D);
     728                }
    729729#endif
    730730#ifdef CR_ARB_texture_cube_map
    731                                 if (tObj == t->unit[u].currentTextureCubeMap)
    732                                 {
    733                                         t->unit[u].currentTextureCubeMap = &(t->baseCubeMap);
    734                                 }
     731                if (tObj == t->unit[u].currentTextureCubeMap)
     732                {
     733                    t->unit[u].currentTextureCubeMap = &(t->baseCubeMap);
     734                }
    735735#endif
    736736#ifdef CR_NV_texture_rectangle
    737                                 if (tObj == t->unit[u].currentTextureRect)
    738                                 {
    739                                         t->unit[u].currentTextureRect = &(t->baseRect);
    740                                 }
    741 #endif
    742                         }
     737                if (tObj == t->unit[u].currentTextureRect)
     738                {
     739                    t->unit[u].currentTextureRect = &(t->baseRect);
     740                }
     741#endif
     742            }
    743743
    744744#ifdef CR_EXT_framebuffer_object
     
    746746            crStateTextureCheckFBOAPs(GL_READ_FRAMEBUFFER, name);
    747747#endif
    748                         crStateDeleteTextureObject(tObj);
    749                 }
    750         }
    751 
    752         DIRTY(tb->dirty, g->neg_bitid);
    753         DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
     748            crStateDeleteTextureObject(tObj);
     749        }
     750    }
     751
     752    DIRTY(tb->dirty, g->neg_bitid);
     753    DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
    754754}
    755755
     
    758758void STATE_APIENTRY crStateClientActiveTextureARB( GLenum texture )
    759759{
    760         CRContext *g = GetCurrentContext();
    761         CRClientState *c = &(g->client);
    762 
    763         FLUSH();
    764 
    765         if (!g->extensions.ARB_multitexture) {
    766                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    767                                                                 "glClientActiveTextureARB not available");
    768                 return;
    769         }
    770 
    771         if (g->current.inBeginEnd)
    772         {
    773                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    774                                                                 "glClientActiveTextureARB called in Begin/End");
    775                 return;
    776         }
    777 
    778         if ( texture < GL_TEXTURE0_ARB ||
    779                         texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
    780         {
    781                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    782                                                                 "crStateClientActiveTexture: unit = %d (max is %d)",
    783                                                                 texture, g->limits.maxTextureUnits );
    784                 return;
    785         }
    786 
    787         c->curClientTextureUnit = texture - GL_TEXTURE0_ARB;
     760    CRContext *g = GetCurrentContext();
     761    CRClientState *c = &(g->client);
     762
     763    FLUSH();
     764
     765    if (!g->extensions.ARB_multitexture) {
     766        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     767                                "glClientActiveTextureARB not available");
     768        return;
     769    }
     770
     771    if (g->current.inBeginEnd)
     772    {
     773        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     774                                "glClientActiveTextureARB called in Begin/End");
     775        return;
     776    }
     777
     778    if ( texture < GL_TEXTURE0_ARB ||
     779            texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
     780    {
     781        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     782                                "crStateClientActiveTexture: unit = %d (max is %d)",
     783                                texture, g->limits.maxTextureUnits );
     784        return;
     785    }
     786
     787    c->curClientTextureUnit = texture - GL_TEXTURE0_ARB;
    788788}
    789789
    790790void STATE_APIENTRY crStateActiveTextureARB( GLenum texture )
    791791{
    792         CRContext *g = GetCurrentContext();
    793         CRTextureState *t = &(g->texture);
    794 
    795         FLUSH();
    796 
    797         if (!g->extensions.ARB_multitexture) {
    798                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    799                                                                 "glActiveTextureARB not available");
    800                 return;
    801         }
    802 
    803         if (g->current.inBeginEnd)
    804         {
    805                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glActiveTextureARB called in Begin/End");
    806                 return;
    807         }
    808 
    809         if ( texture < GL_TEXTURE0_ARB || texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
    810         {
    811                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Bad texture unit passed to crStateActiveTexture: %d (max is %d)", texture, g->limits.maxTextureUnits );
    812                 return;
    813         }
    814 
    815         t->curTextureUnit = texture - GL_TEXTURE0_ARB;
    816 
    817         /* update the current matrix pointer, etc. */
    818         if (g->transform.matrixMode == GL_TEXTURE) {
    819                 crStateMatrixMode(GL_TEXTURE);
    820         }
     792    CRContext *g = GetCurrentContext();
     793    CRTextureState *t = &(g->texture);
     794
     795    FLUSH();
     796
     797    if (!g->extensions.ARB_multitexture) {
     798        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     799                                "glActiveTextureARB not available");
     800        return;
     801    }
     802
     803    if (g->current.inBeginEnd)
     804    {
     805        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glActiveTextureARB called in Begin/End");
     806        return;
     807    }
     808
     809    if ( texture < GL_TEXTURE0_ARB || texture >= GL_TEXTURE0_ARB + g->limits.maxTextureUnits)
     810    {
     811        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Bad texture unit passed to crStateActiveTexture: %d (max is %d)", texture, g->limits.maxTextureUnits );
     812        return;
     813    }
     814
     815    t->curTextureUnit = texture - GL_TEXTURE0_ARB;
     816
     817    /* update the current matrix pointer, etc. */
     818    if (g->transform.matrixMode == GL_TEXTURE) {
     819        crStateMatrixMode(GL_TEXTURE);
     820    }
    821821}
    822822
    823823void STATE_APIENTRY crStateBindTexture(GLenum target, GLuint texture)
    824824{
    825         CRContext *g = GetCurrentContext();
    826         CRTextureState *t = &(g->texture);
    827         CRTextureObj *tobj;
    828         CRStateBits *sb = GetCurrentBits();
    829         CRTextureBits *tb = &(sb->texture);
    830 
    831         FLUSH();
    832 
    833         if (g->current.inBeginEnd)
    834         {
    835                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBindTexture called in Begin/End");
    836                 return;
    837         }
    838 
    839         /* Special Case name = 0 */
    840         if (!texture)
    841         {
    842                 switch (target)
    843                 {
    844                         case GL_TEXTURE_1D:
    845                                 t->unit[t->curTextureUnit].currentTexture1D = &(t->base1D);
    846                                 break;
    847                         case GL_TEXTURE_2D:
    848                                 t->unit[t->curTextureUnit].currentTexture2D = &(t->base2D);
    849                                 break;
     825    CRContext *g = GetCurrentContext();
     826    CRTextureState *t = &(g->texture);
     827    CRTextureObj *tobj;
     828    CRStateBits *sb = GetCurrentBits();
     829    CRTextureBits *tb = &(sb->texture);
     830
     831    FLUSH();
     832
     833    if (g->current.inBeginEnd)
     834    {
     835        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBindTexture called in Begin/End");
     836        return;
     837    }
     838
     839    /* Special Case name = 0 */
     840    if (!texture)
     841    {
     842        switch (target)
     843        {
     844            case GL_TEXTURE_1D:
     845                t->unit[t->curTextureUnit].currentTexture1D = &(t->base1D);
     846                break;
     847            case GL_TEXTURE_2D:
     848                t->unit[t->curTextureUnit].currentTexture2D = &(t->base2D);
     849                break;
    850850#ifdef CR_OPENGL_VERSION_1_2
    851                         case GL_TEXTURE_3D:
    852                                 t->unit[t->curTextureUnit].currentTexture3D = &(t->base3D);
    853                                 break;
     851            case GL_TEXTURE_3D:
     852                t->unit[t->curTextureUnit].currentTexture3D = &(t->base3D);
     853                break;
    854854#endif
    855855#ifdef CR_ARB_texture_cube_map
    856                         case GL_TEXTURE_CUBE_MAP_ARB:
    857                                 if (!g->extensions.ARB_texture_cube_map) {
    858                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    859                                                 "Invalid target passed to glBindTexture: %d", target);
    860                                         return;
    861                                 }
    862                                 t->unit[t->curTextureUnit].currentTextureCubeMap = &(t->baseCubeMap);
    863                                 break;
     856            case GL_TEXTURE_CUBE_MAP_ARB:
     857                if (!g->extensions.ARB_texture_cube_map) {
     858                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     859                        "Invalid target passed to glBindTexture: %d", target);
     860                    return;
     861                }
     862                t->unit[t->curTextureUnit].currentTextureCubeMap = &(t->baseCubeMap);
     863                break;
    864864#endif
    865865#ifdef CR_NV_texture_rectangle
    866                         case GL_TEXTURE_RECTANGLE_NV:
    867                                 if (!g->extensions.NV_texture_rectangle) {
    868                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    869                                                 "Invalid target passed to glBindTexture: %d", target);
    870                                         return;
    871                                 }
    872                                 t->unit[t->curTextureUnit].currentTextureRect = &(t->baseRect);
    873                                 break;
    874 #endif
    875                         default:
    876                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid target passed to glBindTexture: %d", target);
    877                                 return;
    878                 }
    879 
    880                 DIRTY(tb->dirty, g->neg_bitid);
    881                 DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
    882                 return;
    883         }
    884 
    885         /* texture != 0 */
    886         /* Get the texture */
    887         GET_TOBJ(tobj, g, texture);
    888         if (!tobj)
    889         {
    890                 tobj = crStateTextureAllocate_t(g, texture);
    891         }
    892 
    893         /* Check the targets */
    894         if (tobj->target == GL_NONE)
    895         {
    896                 /* Target isn't set so set it now.*/
    897                 tobj->target = target;
    898         }
    899         else if (tobj->target != target)
    900         {
    901                 crWarning( "You called glBindTexture with a target of 0x%x, but the texture you wanted was target 0x%x [1D: %x 2D: %x 3D: %x cube: %x]", (int) target, (int) tobj->target, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP );
    902                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Attempt to bind a texture of diffent dimenions");
    903                 return;
    904         }
    905 
    906         /* Set the current texture */
    907         switch (target)
    908         {
    909                 case GL_TEXTURE_1D:
    910                         t->unit[t->curTextureUnit].currentTexture1D = tobj;
    911                         break;
    912                 case GL_TEXTURE_2D:
    913                         t->unit[t->curTextureUnit].currentTexture2D = tobj;
    914                         break;
     866            case GL_TEXTURE_RECTANGLE_NV:
     867                if (!g->extensions.NV_texture_rectangle) {
     868                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     869                        "Invalid target passed to glBindTexture: %d", target);
     870                    return;
     871                }
     872                t->unit[t->curTextureUnit].currentTextureRect = &(t->baseRect);
     873                break;
     874#endif
     875            default:
     876                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "Invalid target passed to glBindTexture: %d", target);
     877                return;
     878        }
     879
     880        DIRTY(tb->dirty, g->neg_bitid);
     881        DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
     882        return;
     883    }
     884
     885    /* texture != 0 */
     886    /* Get the texture */
     887    GET_TOBJ(tobj, g, texture);
     888    if (!tobj)
     889    {
     890        tobj = crStateTextureAllocate_t(g, texture);
     891    }
     892
     893    /* Check the targets */
     894    if (tobj->target == GL_NONE)
     895    {
     896        /* Target isn't set so set it now.*/
     897        tobj->target = target;
     898    }
     899    else if (tobj->target != target)
     900    {
     901        crWarning( "You called glBindTexture with a target of 0x%x, but the texture you wanted was target 0x%x [1D: %x 2D: %x 3D: %x cube: %x]", (int) target, (int) tobj->target, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP );
     902        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "Attempt to bind a texture of diffent dimenions");
     903        return;
     904    }
     905
     906    /* Set the current texture */
     907    switch (target)
     908    {
     909        case GL_TEXTURE_1D:
     910            t->unit[t->curTextureUnit].currentTexture1D = tobj;
     911            break;
     912        case GL_TEXTURE_2D:
     913            t->unit[t->curTextureUnit].currentTexture2D = tobj;
     914            break;
    915915#ifdef CR_OPENGL_VERSION_1_2
    916                 case GL_TEXTURE_3D:
    917                         t->unit[t->curTextureUnit].currentTexture3D = tobj;
    918                         break;
     916        case GL_TEXTURE_3D:
     917            t->unit[t->curTextureUnit].currentTexture3D = tobj;
     918            break;
    919919#endif
    920920#ifdef CR_ARB_texture_cube_map
    921                 case GL_TEXTURE_CUBE_MAP_ARB:
    922                         t->unit[t->curTextureUnit].currentTextureCubeMap = tobj;
    923                         break;
     921        case GL_TEXTURE_CUBE_MAP_ARB:
     922            t->unit[t->curTextureUnit].currentTextureCubeMap = tobj;
     923            break;
    924924#endif
    925925#ifdef CR_NV_texture_rectangle
    926                 case GL_TEXTURE_RECTANGLE_NV:
    927                         t->unit[t->curTextureUnit].currentTextureRect = tobj;
    928                         break;
    929 #endif
    930                 default:
    931                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    932                                                                         "Invalid target passed to glBindTexture: %d", target);
    933                         return;
    934         }
    935 
    936         DIRTY(tb->dirty, g->neg_bitid);
    937         DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
     926        case GL_TEXTURE_RECTANGLE_NV:
     927            t->unit[t->curTextureUnit].currentTextureRect = tobj;
     928            break;
     929#endif
     930        default:
     931            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     932                                    "Invalid target passed to glBindTexture: %d", target);
     933            return;
     934    }
     935
     936    DIRTY(tb->dirty, g->neg_bitid);
     937    DIRTY(tb->current[t->curTextureUnit], g->neg_bitid);
    938938}
    939939
     
    942942crStateTexParameterfv(GLenum target, GLenum pname, const GLfloat *param)
    943943{
    944         CRContext *g = GetCurrentContext();
    945         CRTextureObj *tobj = NULL;
    946         CRTextureLevel *tl = NULL;
    947         GLenum e = (GLenum) *param;
    948         CRStateBits *sb = GetCurrentBits();
    949         CRTextureBits *tb = &(sb->texture);
    950         unsigned int i;
    951 
    952         FLUSH();
    953 
    954         if (g->current.inBeginEnd)
    955         {
    956                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    957                                         "TexParameterfv called in Begin/End");
    958                 return;
    959         }
    960 
    961         crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
    962         if (!tobj) {
    963                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    964                                         "TexParamterfv(invalid target=0x%x)", target);
    965                 return;
    966         }
    967 
    968         switch (pname)
    969         {
    970                 case GL_TEXTURE_MIN_FILTER:
    971                         if (e != GL_NEAREST &&
    972                                         e != GL_LINEAR &&
    973                                         e != GL_NEAREST_MIPMAP_NEAREST &&
    974                                         e != GL_LINEAR_MIPMAP_NEAREST &&
    975                                         e != GL_NEAREST_MIPMAP_LINEAR &&
    976                                         e != GL_LINEAR_MIPMAP_LINEAR)
    977                         {
    978                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    979                                                         "TexParamterfv: GL_TEXTURE_MIN_FILTER invalid param: %d", e);
    980                                 return;
    981                         }
    982                         tobj->minFilter = e;
    983                         break;
    984                 case GL_TEXTURE_MAG_FILTER:
    985                         if (e != GL_NEAREST && e != GL_LINEAR)
    986                         {
    987                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    988                                                         "TexParamterfv: GL_TEXTURE_MAG_FILTER invalid param: %d", e);
    989                                 return;
    990                         }
    991                         tobj->magFilter = e;
    992                         break;
    993                 case GL_TEXTURE_WRAP_S:
    994                         if (e == GL_CLAMP || e == GL_REPEAT) {
    995                                 tobj->wrapS = e;
    996                         }
     944    CRContext *g = GetCurrentContext();
     945    CRTextureObj *tobj = NULL;
     946    CRTextureLevel *tl = NULL;
     947    GLenum e = (GLenum) *param;
     948    CRStateBits *sb = GetCurrentBits();
     949    CRTextureBits *tb = &(sb->texture);
     950    unsigned int i;
     951
     952    FLUSH();
     953
     954    if (g->current.inBeginEnd)
     955    {
     956        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     957                    "TexParameterfv called in Begin/End");
     958        return;
     959    }
     960
     961    crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
     962    if (!tobj) {
     963        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     964                    "TexParamterfv(invalid target=0x%x)", target);
     965        return;
     966    }
     967
     968    switch (pname)
     969    {
     970        case GL_TEXTURE_MIN_FILTER:
     971            if (e != GL_NEAREST &&
     972                    e != GL_LINEAR &&
     973                    e != GL_NEAREST_MIPMAP_NEAREST &&
     974                    e != GL_LINEAR_MIPMAP_NEAREST &&
     975                    e != GL_NEAREST_MIPMAP_LINEAR &&
     976                    e != GL_LINEAR_MIPMAP_LINEAR)
     977            {
     978                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     979                            "TexParamterfv: GL_TEXTURE_MIN_FILTER invalid param: %d", e);
     980                return;
     981            }
     982            tobj->minFilter = e;
     983            break;
     984        case GL_TEXTURE_MAG_FILTER:
     985            if (e != GL_NEAREST && e != GL_LINEAR)
     986            {
     987                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     988                            "TexParamterfv: GL_TEXTURE_MAG_FILTER invalid param: %d", e);
     989                return;
     990            }
     991            tobj->magFilter = e;
     992            break;
     993        case GL_TEXTURE_WRAP_S:
     994            if (e == GL_CLAMP || e == GL_REPEAT) {
     995                tobj->wrapS = e;
     996            }
    997997#ifdef CR_OPENGL_VERSION_1_2
    998                         else if (e == GL_CLAMP_TO_EDGE) {
    999                                 tobj->wrapS = e;
    1000                         }
     998            else if (e == GL_CLAMP_TO_EDGE) {
     999                tobj->wrapS = e;
     1000            }
    10011001#endif
    10021002#ifdef GL_CLAMP_TO_EDGE_EXT
    1003                         else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
    1004                                 tobj->wrapS = e;
    1005                         }
     1003            else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
     1004                tobj->wrapS = e;
     1005            }
    10061006#endif
    10071007#ifdef CR_ARB_texture_border_clamp
    1008                         else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
    1009                                 tobj->wrapS = e;
    1010                         }
     1008            else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
     1009                tobj->wrapS = e;
     1010            }
    10111011#endif
    10121012#ifdef CR_ARB_texture_mirrored_repeat
    1013                         else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
    1014                                 tobj->wrapS = e;
    1015                         }
    1016 #endif
    1017                         else {
    1018                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1019                                         "TexParameterfv: GL_TEXTURE_WRAP_S invalid param: 0x%x", e);
    1020                                 return;
    1021                         }
    1022                         break;
    1023                 case GL_TEXTURE_WRAP_T:
    1024                         if (e == GL_CLAMP || e == GL_REPEAT) {
    1025                                 tobj->wrapT = e;
    1026                         }
     1013            else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
     1014                tobj->wrapS = e;
     1015            }
     1016#endif
     1017            else {
     1018                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1019                    "TexParameterfv: GL_TEXTURE_WRAP_S invalid param: 0x%x", e);
     1020                return;
     1021            }
     1022            break;
     1023        case GL_TEXTURE_WRAP_T:
     1024            if (e == GL_CLAMP || e == GL_REPEAT) {
     1025                tobj->wrapT = e;
     1026            }
    10271027#ifdef CR_OPENGL_VERSION_1_2
    1028                         else if (e == GL_CLAMP_TO_EDGE) {
    1029                                 tobj->wrapT = e;
    1030                         }
     1028            else if (e == GL_CLAMP_TO_EDGE) {
     1029                tobj->wrapT = e;
     1030            }
    10311031#endif
    10321032#ifdef GL_CLAMP_TO_EDGE_EXT
    1033                         else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
    1034                                 tobj->wrapT = e;
    1035                         }
     1033            else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
     1034                tobj->wrapT = e;
     1035            }
    10361036#endif
    10371037#ifdef CR_ARB_texture_border_clamp
    1038                         else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
    1039                                 tobj->wrapT = e;
    1040                         }
     1038            else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
     1039                tobj->wrapT = e;
     1040            }
    10411041#endif
    10421042#ifdef CR_ARB_texture_mirrored_repeat
    1043                         else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
    1044                                 tobj->wrapT = e;
    1045                         }
    1046 #endif
    1047                         else {
    1048                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1049                                         "TexParameterfv: GL_TEXTURE_WRAP_T invalid param: 0x%x", e);
    1050                                 return;
    1051                         }
    1052                         break;
     1043            else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
     1044                tobj->wrapT = e;
     1045            }
     1046#endif
     1047            else {
     1048                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1049                    "TexParameterfv: GL_TEXTURE_WRAP_T invalid param: 0x%x", e);
     1050                return;
     1051            }
     1052            break;
    10531053#ifdef CR_OPENGL_VERSION_1_2
    1054                 case GL_TEXTURE_WRAP_R:
    1055                         if (e == GL_CLAMP || e == GL_REPEAT) {
    1056                                 tobj->wrapR = e;
    1057                         }
    1058                         else if (e == GL_CLAMP_TO_EDGE) {
    1059                                 tobj->wrapR = e;
    1060                         }
     1054        case GL_TEXTURE_WRAP_R:
     1055            if (e == GL_CLAMP || e == GL_REPEAT) {
     1056                tobj->wrapR = e;
     1057            }
     1058            else if (e == GL_CLAMP_TO_EDGE) {
     1059                tobj->wrapR = e;
     1060            }
    10611061#ifdef GL_CLAMP_TO_EDGE_EXT
    1062                         else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
    1063                                 tobj->wrapR = e;
    1064                         }
     1062            else if (e == GL_CLAMP_TO_EDGE_EXT && g->extensions.EXT_texture_edge_clamp) {
     1063                tobj->wrapR = e;
     1064            }
    10651065#endif
    10661066#ifdef CR_ARB_texture_border_clamp
    1067                         else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
    1068                                 tobj->wrapR = e;
    1069                         }
     1067            else if (e == GL_CLAMP_TO_BORDER_ARB && g->extensions.ARB_texture_border_clamp) {
     1068                tobj->wrapR = e;
     1069            }
    10701070#endif
    10711071#ifdef CR_ARB_texture_mirrored_repeat
    1072                         else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
    1073                                 tobj->wrapR = e;
    1074                         }
    1075 #endif
    1076                         else {
    1077                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1078                                         "TexParameterfv: GL_TEXTURE_WRAP_R invalid param: 0x%x", e);
    1079                                 return;
    1080                         }
    1081                         break;
    1082                 case GL_TEXTURE_PRIORITY:
    1083                         tobj->priority = param[0];
    1084                         break;
    1085                 case GL_TEXTURE_MIN_LOD:
    1086                         tobj->minLod = param[0];
    1087                         break;
    1088                 case GL_TEXTURE_MAX_LOD:
    1089                         tobj->maxLod = param[0];
    1090                         break;
    1091                 case GL_TEXTURE_BASE_LEVEL:
    1092                         if (e < 0.0f)
    1093                         {
    1094                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1095                                         "TexParameterfv: GL_TEXTURE_BASE_LEVEL invalid param: 0x%x", e);
    1096                                 return;
    1097                         }
    1098                         tobj->baseLevel = e;
    1099                         break;
    1100                 case GL_TEXTURE_MAX_LEVEL:
    1101                         if (e < 0.0f)
    1102                         {
    1103                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1104                                         "TexParameterfv: GL_TEXTURE_MAX_LEVEL invalid param: 0x%x", e);
    1105                                 return;
    1106                         }
    1107                         tobj->maxLevel = e;
    1108                         break;
    1109 #endif
    1110                 case GL_TEXTURE_BORDER_COLOR:
    1111                         tobj->borderColor.r = param[0];
    1112                         tobj->borderColor.g = param[1];
    1113                         tobj->borderColor.b = param[2];
    1114                         tobj->borderColor.a = param[3];
    1115                         break;
     1072            else if (e == GL_MIRRORED_REPEAT_ARB && g->extensions.ARB_texture_mirrored_repeat) {
     1073                tobj->wrapR = e;
     1074            }
     1075#endif
     1076            else {
     1077                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1078                    "TexParameterfv: GL_TEXTURE_WRAP_R invalid param: 0x%x", e);
     1079                return;
     1080            }
     1081            break;
     1082        case GL_TEXTURE_PRIORITY:
     1083            tobj->priority = param[0];
     1084            break;
     1085        case GL_TEXTURE_MIN_LOD:
     1086            tobj->minLod = param[0];
     1087            break;
     1088        case GL_TEXTURE_MAX_LOD:
     1089            tobj->maxLod = param[0];
     1090            break;
     1091        case GL_TEXTURE_BASE_LEVEL:
     1092            if (e < 0.0f)
     1093            {
     1094                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1095                    "TexParameterfv: GL_TEXTURE_BASE_LEVEL invalid param: 0x%x", e);
     1096                return;
     1097            }
     1098            tobj->baseLevel = e;
     1099            break;
     1100        case GL_TEXTURE_MAX_LEVEL:
     1101            if (e < 0.0f)
     1102            {
     1103                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1104                    "TexParameterfv: GL_TEXTURE_MAX_LEVEL invalid param: 0x%x", e);
     1105                return;
     1106            }
     1107            tobj->maxLevel = e;
     1108            break;
     1109#endif
     1110        case GL_TEXTURE_BORDER_COLOR:
     1111            tobj->borderColor.r = param[0];
     1112            tobj->borderColor.g = param[1];
     1113            tobj->borderColor.b = param[2];
     1114            tobj->borderColor.a = param[3];
     1115            break;
    11161116#ifdef CR_EXT_texture_filter_anisotropic
    1117                 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
    1118                         if (g->extensions.EXT_texture_filter_anisotropic) {
    1119                                 if (param[0] < 1.0f)
    1120                                 {
    1121                                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    1122                                                 "TexParameterfv: GL_TEXTURE_MAX_ANISOTROPY_EXT called with parameter less than 1: %f", param[0]);
    1123                                         return;
    1124                                 }
    1125                                 tobj->maxAnisotropy = param[0];
    1126                                 if (tobj->maxAnisotropy > g->limits.maxTextureAnisotropy)
    1127                                 {
    1128                                         tobj->maxAnisotropy = g->limits.maxTextureAnisotropy;
    1129                                 }
    1130                         }
    1131                         break;
     1117        case GL_TEXTURE_MAX_ANISOTROPY_EXT:
     1118            if (g->extensions.EXT_texture_filter_anisotropic) {
     1119                if (param[0] < 1.0f)
     1120                {
     1121                    crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1122                        "TexParameterfv: GL_TEXTURE_MAX_ANISOTROPY_EXT called with parameter less than 1: %f", param[0]);
     1123                    return;
     1124                }
     1125                tobj->maxAnisotropy = param[0];
     1126                if (tobj->maxAnisotropy > g->limits.maxTextureAnisotropy)
     1127                {
     1128                    tobj->maxAnisotropy = g->limits.maxTextureAnisotropy;
     1129                }
     1130            }
     1131            break;
    11321132#endif
    11331133#ifdef CR_ARB_depth_texture
    1134                 case GL_DEPTH_TEXTURE_MODE_ARB:
    1135                         if (g->extensions.ARB_depth_texture) {
    1136                                 if (param[0] == GL_LUMINANCE ||
    1137                                     param[0] == GL_INTENSITY ||
    1138                                     param[0] == GL_ALPHA) {
    1139                                         tobj->depthMode = (GLenum) param[0];
    1140                                 }
    1141                                 else
    1142                                 {
    1143                                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    1144                                                 "TexParameterfv: GL_DEPTH_TEXTURE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
    1145                                         return;
    1146                                 }
    1147                         }
    1148                         break;
     1134        case GL_DEPTH_TEXTURE_MODE_ARB:
     1135            if (g->extensions.ARB_depth_texture) {
     1136                if (param[0] == GL_LUMINANCE ||
     1137                    param[0] == GL_INTENSITY ||
     1138                    param[0] == GL_ALPHA) {
     1139                    tobj->depthMode = (GLenum) param[0];
     1140                }
     1141                else
     1142                {
     1143                    crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1144                        "TexParameterfv: GL_DEPTH_TEXTURE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
     1145                    return;
     1146                }
     1147            }
     1148            break;
    11491149#endif
    11501150#ifdef CR_ARB_shadow
    1151                 case GL_TEXTURE_COMPARE_MODE_ARB:
    1152                         if (g->extensions.ARB_shadow) {
    1153                                 if (param[0] == GL_NONE ||
    1154                                     param[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
    1155                                         tobj->compareMode = (GLenum) param[0];
    1156                                 }
    1157                                 else
    1158                                 {
    1159                                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    1160                                                 "TexParameterfv: GL_TEXTURE_COMPARE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
    1161                                         return;
    1162                                 }
    1163                         }
    1164                         break;
    1165                 case GL_TEXTURE_COMPARE_FUNC_ARB:
    1166                         if (g->extensions.ARB_shadow) {
    1167                                 if (param[0] == GL_LEQUAL ||
    1168                                     param[0] == GL_GEQUAL) {
    1169                                         tobj->compareFunc = (GLenum) param[0];
    1170                                 }
    1171                         }
     1151        case GL_TEXTURE_COMPARE_MODE_ARB:
     1152            if (g->extensions.ARB_shadow) {
     1153                if (param[0] == GL_NONE ||
     1154                    param[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
     1155                    tobj->compareMode = (GLenum) param[0];
     1156                }
     1157                else
     1158                {
     1159                    crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1160                        "TexParameterfv: GL_TEXTURE_COMPARE_MODE_ARB called with invalid parameter: 0x%x", param[0]);
     1161                    return;
     1162                }
     1163            }
     1164            break;
     1165        case GL_TEXTURE_COMPARE_FUNC_ARB:
     1166            if (g->extensions.ARB_shadow) {
     1167                if (param[0] == GL_LEQUAL ||
     1168                    param[0] == GL_GEQUAL) {
     1169                    tobj->compareFunc = (GLenum) param[0];
     1170                }
     1171            }
    11721172#ifdef CR_EXT_shadow_funcs
    1173                         else if (g->extensions.EXT_shadow_funcs) {
    1174                                 if (param[0] == GL_LEQUAL ||
    1175                                     param[0] == GL_GEQUAL ||
    1176                                     param[0] == GL_LESS ||
    1177                                     param[0] == GL_GREATER ||
    1178                                     param[0] == GL_ALWAYS ||
    1179                                     param[0] == GL_NEVER ) {
    1180                                         tobj->compareFunc = (GLenum) param[0];
    1181                                 }
    1182                         }
    1183 #endif
    1184                         else {
    1185                                         crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    1186                                                 "TexParameterfv: GL_TEXTURE_COMPARE_FUNC_ARB called with invalid parameter: 0x%x", param[0]);
    1187                                         return;
    1188                         }
    1189                         break;
     1173            else if (g->extensions.EXT_shadow_funcs) {
     1174                if (param[0] == GL_LEQUAL ||
     1175                    param[0] == GL_GEQUAL ||
     1176                    param[0] == GL_LESS ||
     1177                    param[0] == GL_GREATER ||
     1178                    param[0] == GL_ALWAYS ||
     1179                    param[0] == GL_NEVER ) {
     1180                    tobj->compareFunc = (GLenum) param[0];
     1181                }
     1182            }
     1183#endif
     1184            else {
     1185                    crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     1186                        "TexParameterfv: GL_TEXTURE_COMPARE_FUNC_ARB called with invalid parameter: 0x%x", param[0]);
     1187                    return;
     1188            }
     1189            break;
    11901190#endif
    11911191#ifdef CR_ARB_shadow_ambient
    1192                 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
    1193                         if (g->extensions.ARB_shadow_ambient) {
    1194                                 tobj->compareFailValue = param[0];
    1195                         }
    1196                         break;
     1192        case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
     1193            if (g->extensions.ARB_shadow_ambient) {
     1194                tobj->compareFailValue = param[0];
     1195            }
     1196            break;
    11971197#endif
    11981198#ifdef CR_SGIS_generate_mipmap
    1199                 case GL_GENERATE_MIPMAP_SGIS:
    1200                         if (g->extensions.SGIS_generate_mipmap) {
    1201                                 tobj->generateMipmap = param[0] ? GL_TRUE : GL_FALSE;
    1202                         }
    1203                         break;
    1204 #endif
    1205                 default:
    1206                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1207                                 "TexParamterfv: Invalid pname: %d", pname);
    1208                         return;
    1209         }
    1210 
    1211         DIRTY(tobj->dirty, g->neg_bitid);
    1212         for (i = 0; i < g->limits.maxTextureUnits; i++)
    1213         {
    1214                 DIRTY(tobj->paramsBit[i], g->neg_bitid);
    1215         }
    1216         DIRTY(tb->dirty, g->neg_bitid);
     1199        case GL_GENERATE_MIPMAP_SGIS:
     1200            if (g->extensions.SGIS_generate_mipmap) {
     1201                tobj->generateMipmap = param[0] ? GL_TRUE : GL_FALSE;
     1202            }
     1203            break;
     1204#endif
     1205        default:
     1206            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1207                "TexParamterfv: Invalid pname: %d", pname);
     1208            return;
     1209    }
     1210
     1211    DIRTY(tobj->dirty, g->neg_bitid);
     1212    for (i = 0; i < g->limits.maxTextureUnits; i++)
     1213    {
     1214        DIRTY(tobj->paramsBit[i], g->neg_bitid);
     1215    }
     1216    DIRTY(tb->dirty, g->neg_bitid);
    12171217}
    12181218
     
    12211221crStateTexParameteriv(GLenum target, GLenum pname, const GLint *param)
    12221222{
    1223         GLfloat f_param;
    1224         GLcolor f_color;
    1225         switch (pname)
    1226         {
    1227                 case GL_TEXTURE_MIN_FILTER:
    1228                 case GL_TEXTURE_MAG_FILTER:
    1229                 case GL_TEXTURE_WRAP_S:
    1230                 case GL_TEXTURE_WRAP_T:
     1223    GLfloat f_param;
     1224    GLcolor f_color;
     1225    switch (pname)
     1226    {
     1227        case GL_TEXTURE_MIN_FILTER:
     1228        case GL_TEXTURE_MAG_FILTER:
     1229        case GL_TEXTURE_WRAP_S:
     1230        case GL_TEXTURE_WRAP_T:
    12311231#ifdef CR_OPENGL_VERSION_1_2
    1232                 case GL_TEXTURE_WRAP_R:
    1233                 case GL_TEXTURE_PRIORITY:
    1234                 case GL_TEXTURE_MIN_LOD:
    1235                 case GL_TEXTURE_MAX_LOD:
    1236                 case GL_TEXTURE_BASE_LEVEL:
    1237                 case GL_TEXTURE_MAX_LEVEL:
     1232        case GL_TEXTURE_WRAP_R:
     1233        case GL_TEXTURE_PRIORITY:
     1234        case GL_TEXTURE_MIN_LOD:
     1235        case GL_TEXTURE_MAX_LOD:
     1236        case GL_TEXTURE_BASE_LEVEL:
     1237        case GL_TEXTURE_MAX_LEVEL:
    12381238#endif
    12391239#ifdef CR_EXT_texture_filter_anisotropic
    1240                 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
     1240        case GL_TEXTURE_MAX_ANISOTROPY_EXT:
    12411241#endif
    12421242#ifdef CR_ARB_depth_texture
    1243                 case GL_DEPTH_TEXTURE_MODE_ARB:
     1243        case GL_DEPTH_TEXTURE_MODE_ARB:
    12441244#endif
    12451245#ifdef CR_ARB_shadow
    1246                 case GL_TEXTURE_COMPARE_MODE_ARB:
    1247                 case GL_TEXTURE_COMPARE_FUNC_ARB:
     1246        case GL_TEXTURE_COMPARE_MODE_ARB:
     1247        case GL_TEXTURE_COMPARE_FUNC_ARB:
    12481248#endif
    12491249#ifdef CR_ARB_shadow_ambinet
    1250                 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
     1250        case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
    12511251#endif
    12521252#ifdef CR_SGIS_generate_mipmap
    1253                 case GL_GENERATE_MIPMAP_SGIS:
    1254 #endif
    1255                         f_param = (GLfloat) (*param);
    1256                         crStateTexParameterfv( target, pname, &(f_param) );
    1257                         break;
    1258                 case GL_TEXTURE_BORDER_COLOR:
    1259                         f_color.r = ((GLfloat) param[0])/CR_MAXINT;
    1260                         f_color.g = ((GLfloat) param[1])/CR_MAXINT;
    1261                         f_color.b = ((GLfloat) param[2])/CR_MAXINT;
    1262                         f_color.a = ((GLfloat) param[3])/CR_MAXINT;
    1263                         crStateTexParameterfv( target, pname, (const GLfloat *) &(f_color) );
    1264                         break;
    1265                 default:
    1266                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1267                                 "TexParamteriv: Invalid pname: %d", pname);
    1268                         return;
    1269         }
     1253        case GL_GENERATE_MIPMAP_SGIS:
     1254#endif
     1255            f_param = (GLfloat) (*param);
     1256            crStateTexParameterfv( target, pname, &(f_param) );
     1257            break;
     1258        case GL_TEXTURE_BORDER_COLOR:
     1259            f_color.r = ((GLfloat) param[0])/CR_MAXINT;
     1260            f_color.g = ((GLfloat) param[1])/CR_MAXINT;
     1261            f_color.b = ((GLfloat) param[2])/CR_MAXINT;
     1262            f_color.a = ((GLfloat) param[3])/CR_MAXINT;
     1263            crStateTexParameterfv( target, pname, (const GLfloat *) &(f_color) );
     1264            break;
     1265        default:
     1266            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1267                "TexParamteriv: Invalid pname: %d", pname);
     1268            return;
     1269    }
    12701270}
    12711271
     
    12741274crStateTexParameterf(GLenum target, GLenum pname, GLfloat param)
    12751275{
    1276         crStateTexParameterfv( target, pname, &param );
     1276    crStateTexParameterfv( target, pname, &param );
    12771277}
    12781278
     
    12801280void STATE_APIENTRY
    12811281crStateTexParameteri(GLenum target, GLenum pname, GLint param) {
    1282         GLfloat f_param = (GLfloat) param;
    1283         crStateTexParameterfv( target, pname, &f_param );
     1282    GLfloat f_param = (GLfloat) param;
     1283    crStateTexParameterfv( target, pname, &f_param );
    12841284}
    12851285
     
    12881288crStateTexEnvfv(GLenum target, GLenum pname, const GLfloat *param)
    12891289{
    1290         CRContext *g = GetCurrentContext();
    1291         CRTextureState *t = &(g->texture);
    1292         CRStateBits *sb = GetCurrentBits();
    1293         CRTextureBits *tb = &(sb->texture);
    1294         GLenum e;
    1295         GLcolorf c;
    1296         GLuint stage = 0;
    1297 
    1298         (void) stage;
    1299 
    1300         FLUSH();
    1301 
    1302         if (g->current.inBeginEnd)
    1303         {
    1304                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    1305                                         "glTexEnvfv called in begin/end");
    1306                 return;
    1307         }
     1290    CRContext *g = GetCurrentContext();
     1291    CRTextureState *t = &(g->texture);
     1292    CRStateBits *sb = GetCurrentBits();
     1293    CRTextureBits *tb = &(sb->texture);
     1294    GLenum e;
     1295    GLcolorf c;
     1296    GLuint stage = 0;
     1297
     1298    (void) stage;
     1299
     1300    FLUSH();
     1301
     1302    if (g->current.inBeginEnd)
     1303    {
     1304        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     1305                    "glTexEnvfv called in begin/end");
     1306        return;
     1307    }
    13081308
    13091309#if CR_EXT_texture_lod_bias
    1310         if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
    1311                 if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
    1312                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
    1313                 }
    1314                 else {
    1315                         t->unit[t->curTextureUnit].lodBias = *param;
    1316                         DIRTY(tb->envBit[t->curTextureUnit], g->neg_bitid);
    1317                         DIRTY(tb->dirty, g->neg_bitid);
    1318                 }
    1319                 return;
    1320         }
    1321         else
     1310    if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
     1311        if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
     1312            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
     1313        }
     1314        else {
     1315            t->unit[t->curTextureUnit].lodBias = *param;
     1316            DIRTY(tb->envBit[t->curTextureUnit], g->neg_bitid);
     1317            DIRTY(tb->dirty, g->neg_bitid);
     1318        }
     1319        return;
     1320    }
     1321    else
    13221322#endif
    13231323#if CR_ARB_point_sprite
    1324         if (target == GL_POINT_SPRITE_ARB) {
    1325                 if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
    1326                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
    1327                 }
    1328                 else {
    1329                         CRPointBits *pb = &(sb->point);
    1330                         g->point.coordReplacement[t->curTextureUnit] = *param ? GL_TRUE : GL_FALSE;
    1331                         DIRTY(pb->coordReplacement[t->curTextureUnit], g->neg_bitid);
    1332                         DIRTY(pb->dirty, g->neg_bitid);
    1333                 }
    1334                 return;
    1335         }
    1336         else
    1337 #endif
    1338         if (target != GL_TEXTURE_ENV)
    1339         {
    1340                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1341                                         "glTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
    1342                 return;
    1343         }
    1344 
    1345         switch (pname)
    1346         {
    1347                 case GL_TEXTURE_ENV_MODE:
    1348                         e = (GLenum) *param;
    1349                         if (e != GL_MODULATE &&
    1350                                         e != GL_DECAL &&
    1351                                         e != GL_BLEND &&
    1352                                         e != GL_ADD &&
    1353                                         e != GL_REPLACE &&
    1354                                         e != GL_COMBINE_ARB)
    1355                         {
    1356                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1357                                                         "glTexEnvfv: invalid param: %f", *param);
    1358                                 return;
    1359                         }
    1360                         t->unit[t->curTextureUnit].envMode = e;
    1361                         break;
    1362                 case GL_TEXTURE_ENV_COLOR:
    1363                         c.r = param[0];
    1364                         c.g = param[1];
    1365                         c.b = param[2];
    1366                         c.a = param[3];
    1367                         if (c.r > 1.0f) c.r = 1.0f;
    1368                         if (c.g > 1.0f) c.g = 1.0f;
    1369                         if (c.b > 1.0f) c.b = 1.0f;
    1370                         if (c.a > 1.0f) c.a = 1.0f;
    1371                         if (c.r < 0.0f) c.r = 0.0f;
    1372                         if (c.g < 0.0f) c.g = 0.0f;
    1373                         if (c.b < 0.0f) c.b = 0.0f;
    1374                         if (c.a < 0.0f) c.a = 0.0f;
    1375                         t->unit[t->curTextureUnit].envColor = c;
    1376                         break;
     1324    if (target == GL_POINT_SPRITE_ARB) {
     1325        if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
     1326            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnv");
     1327        }
     1328        else {
     1329            CRPointBits *pb = &(sb->point);
     1330            g->point.coordReplacement[t->curTextureUnit] = *param ? GL_TRUE : GL_FALSE;
     1331            DIRTY(pb->coordReplacement[t->curTextureUnit], g->neg_bitid);
     1332            DIRTY(pb->dirty, g->neg_bitid);
     1333        }
     1334        return;
     1335    }
     1336    else
     1337#endif
     1338    if (target != GL_TEXTURE_ENV)
     1339    {
     1340        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1341                    "glTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
     1342        return;
     1343    }
     1344
     1345    switch (pname)
     1346    {
     1347        case GL_TEXTURE_ENV_MODE:
     1348            e = (GLenum) *param;
     1349            if (e != GL_MODULATE &&
     1350                    e != GL_DECAL &&
     1351                    e != GL_BLEND &&
     1352                    e != GL_ADD &&
     1353                    e != GL_REPLACE &&
     1354                    e != GL_COMBINE_ARB)
     1355            {
     1356                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1357                            "glTexEnvfv: invalid param: %f", *param);
     1358                return;
     1359            }
     1360            t->unit[t->curTextureUnit].envMode = e;
     1361            break;
     1362        case GL_TEXTURE_ENV_COLOR:
     1363            c.r = param[0];
     1364            c.g = param[1];
     1365            c.b = param[2];
     1366            c.a = param[3];
     1367            if (c.r > 1.0f) c.r = 1.0f;
     1368            if (c.g > 1.0f) c.g = 1.0f;
     1369            if (c.b > 1.0f) c.b = 1.0f;
     1370            if (c.a > 1.0f) c.a = 1.0f;
     1371            if (c.r < 0.0f) c.r = 0.0f;
     1372            if (c.g < 0.0f) c.g = 0.0f;
     1373            if (c.b < 0.0f) c.b = 0.0f;
     1374            if (c.a < 0.0f) c.a = 0.0f;
     1375            t->unit[t->curTextureUnit].envColor = c;
     1376            break;
    13771377
    13781378#ifdef CR_ARB_texture_env_combine
    1379                 case GL_COMBINE_RGB_ARB:
    1380                         e = (GLenum) (GLint) *param;
    1381                         if (g->extensions.ARB_texture_env_combine &&
    1382                                         (e == GL_REPLACE ||
    1383                                         e == GL_MODULATE ||
    1384                                         e == GL_ADD ||
    1385                                         e == GL_ADD_SIGNED_ARB ||
    1386                                         e == GL_INTERPOLATE_ARB ||
    1387                                         e == GL_SUBTRACT_ARB)) {
    1388                                 t->unit[t->curTextureUnit].combineModeRGB = e;
    1389                         }
     1379        case GL_COMBINE_RGB_ARB:
     1380            e = (GLenum) (GLint) *param;
     1381            if (g->extensions.ARB_texture_env_combine &&
     1382                    (e == GL_REPLACE ||
     1383                    e == GL_MODULATE ||
     1384                    e == GL_ADD ||
     1385                    e == GL_ADD_SIGNED_ARB ||
     1386                    e == GL_INTERPOLATE_ARB ||
     1387                    e == GL_SUBTRACT_ARB)) {
     1388                t->unit[t->curTextureUnit].combineModeRGB = e;
     1389            }
    13901390#ifdef CR_ARB_texture_env_dot3
    1391                         else if (g->extensions.ARB_texture_env_dot3 &&
    1392                                                         (e == GL_DOT3_RGB_ARB ||
    1393                                                                 e == GL_DOT3_RGBA_ARB ||
    1394                                                                 e == GL_DOT3_RGB_EXT ||
    1395                                                                 e == GL_DOT3_RGBA_EXT)) {
    1396                                 t->unit[t->curTextureUnit].combineModeRGB = e;
    1397                         }
    1398 #endif
    1399                         else {
    1400                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x", e);
    1401                                 return;
    1402                         }
    1403                         break;
    1404                 case GL_COMBINE_ALPHA_EXT:
    1405                         e = (GLenum) *param;
    1406                         if (g->extensions.ARB_texture_env_combine &&
    1407                                         (e == GL_REPLACE ||
    1408                                         e == GL_MODULATE ||
    1409                                         e == GL_ADD ||
    1410                                         e == GL_ADD_SIGNED_ARB ||
    1411                                         e == GL_INTERPOLATE_ARB ||
    1412                                         e == GL_SUBTRACT_ARB)) {
    1413                                 t->unit[t->curTextureUnit].combineModeA = e;
    1414                         }
    1415                         else {
    1416                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    1417                                 return;
    1418                         }
    1419                         break;
    1420                 case GL_SOURCE0_RGB_ARB:
    1421                 case GL_SOURCE1_RGB_ARB:
    1422                 case GL_SOURCE2_RGB_ARB:
    1423                         e = (GLenum) *param;
    1424                         stage = pname - GL_SOURCE0_RGB_ARB;
    1425                         if (g->extensions.ARB_texture_env_combine &&
    1426                                         (e == GL_TEXTURE ||
    1427                                         e == GL_CONSTANT_ARB ||
    1428                                         e == GL_PRIMARY_COLOR_ARB ||
    1429                                         e == GL_PREVIOUS_ARB)) {
    1430                                 t->unit[t->curTextureUnit].combineSourceRGB[stage] = e;
    1431                         }
    1432                         else if (g->extensions.ARB_texture_env_crossbar &&
    1433                                                         e >= GL_TEXTURE0_ARB &&
    1434                                                         e < GL_TEXTURE0_ARB + g->limits.maxTextureUnits) {
    1435                                 t->unit[t->curTextureUnit].combineSourceRGB[stage] = e;
    1436                         }
    1437                         else {
    1438                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    1439                                 return;
    1440                         }
    1441                         break;
    1442                 case GL_SOURCE0_ALPHA_ARB:
    1443                 case GL_SOURCE1_ALPHA_ARB:
    1444                 case GL_SOURCE2_ALPHA_ARB:
    1445                         e = (GLenum) *param;
    1446                         stage = pname - GL_SOURCE0_ALPHA_ARB;
    1447                         if (g->extensions.ARB_texture_env_combine &&
    1448                                         (e == GL_TEXTURE ||
    1449                                         e == GL_CONSTANT_ARB ||
    1450                                         e == GL_PRIMARY_COLOR_ARB ||
    1451                                         e == GL_PREVIOUS_ARB)) {
    1452                                 t->unit[t->curTextureUnit].combineSourceA[stage] = e;
    1453                         }
    1454                         else if (g->extensions.ARB_texture_env_crossbar &&
    1455                                                         e >= GL_TEXTURE0_ARB &&
    1456                                                         e < GL_TEXTURE0_ARB + g->limits.maxTextureUnits) {
    1457                                 t->unit[t->curTextureUnit].combineSourceA[stage] = e;
    1458                         }
    1459                         else {
    1460                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    1461                                 return;
    1462                         }
    1463                         break;
    1464                 case GL_OPERAND0_RGB_ARB:
    1465                 case GL_OPERAND1_RGB_ARB:
    1466                 case GL_OPERAND2_RGB_ARB:
    1467                         e = (GLenum) *param;
    1468                         stage = pname - GL_OPERAND0_RGB_ARB;
    1469                         if (g->extensions.ARB_texture_env_combine &&
    1470                                         (e == GL_SRC_COLOR ||
    1471                                         e == GL_ONE_MINUS_SRC_COLOR ||
    1472                                         e == GL_SRC_ALPHA ||
    1473                                         e == GL_ONE_MINUS_SRC_ALPHA)) {
    1474                                 t->unit[t->curTextureUnit].combineOperandRGB[stage] = e;
    1475                         }
    1476                         else {
    1477                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
    1478                                 return;
    1479                         }
    1480                         break;
    1481                 case GL_OPERAND0_ALPHA_ARB:
    1482                 case GL_OPERAND1_ALPHA_ARB:
    1483                 case GL_OPERAND2_ALPHA_ARB:
    1484                         e = (GLenum) *param;
    1485                         stage = pname - GL_OPERAND0_ALPHA_ARB;
    1486                         if (g->extensions.ARB_texture_env_combine &&
    1487                                         (e == GL_SRC_ALPHA ||
    1488                                         e == GL_ONE_MINUS_SRC_ALPHA)) {
    1489                                 t->unit[t->curTextureUnit].combineOperandA[stage] = e;
    1490                         }
    1491                         else {
    1492                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x)", e);
    1493                                 return;
    1494                         }
    1495                         break;
    1496                 case GL_RGB_SCALE_ARB:
    1497                         if (g->extensions.ARB_texture_env_combine &&
    1498                                         (*param == 1.0 ||
    1499                                         *param == 2.0 ||
    1500                                         *param == 4.0)) {
    1501                                 t->unit[t->curTextureUnit].combineScaleRGB = *param;
    1502                         }
    1503                         else {
    1504                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
    1505                                 return;
    1506                         }
    1507                         break;
    1508                 case GL_ALPHA_SCALE:
    1509                         if (g->extensions.ARB_texture_env_combine &&
    1510                                         (*param == 1.0 ||
    1511                                         *param == 2.0 ||
    1512                                         *param == 4.0)) {
    1513                                 t->unit[t->curTextureUnit].combineScaleA = *param;
    1514                         }
    1515                         else {
    1516                                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
    1517                                 return;
    1518                         }
    1519                 break;
     1391            else if (g->extensions.ARB_texture_env_dot3 &&
     1392                            (e == GL_DOT3_RGB_ARB ||
     1393                                e == GL_DOT3_RGBA_ARB ||
     1394                                e == GL_DOT3_RGB_EXT ||
     1395                                e == GL_DOT3_RGBA_EXT)) {
     1396                t->unit[t->curTextureUnit].combineModeRGB = e;
     1397            }
     1398#endif
     1399            else {
     1400                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x", e);
     1401                return;
     1402            }
     1403            break;
     1404        case GL_COMBINE_ALPHA_EXT:
     1405            e = (GLenum) *param;
     1406            if (g->extensions.ARB_texture_env_combine &&
     1407                    (e == GL_REPLACE ||
     1408                    e == GL_MODULATE ||
     1409                    e == GL_ADD ||
     1410                    e == GL_ADD_SIGNED_ARB ||
     1411                    e == GL_INTERPOLATE_ARB ||
     1412                    e == GL_SUBTRACT_ARB)) {
     1413                t->unit[t->curTextureUnit].combineModeA = e;
     1414            }
     1415            else {
     1416                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1417                return;
     1418            }
     1419            break;
     1420        case GL_SOURCE0_RGB_ARB:
     1421        case GL_SOURCE1_RGB_ARB:
     1422        case GL_SOURCE2_RGB_ARB:
     1423            e = (GLenum) *param;
     1424            stage = pname - GL_SOURCE0_RGB_ARB;
     1425            if (g->extensions.ARB_texture_env_combine &&
     1426                    (e == GL_TEXTURE ||
     1427                    e == GL_CONSTANT_ARB ||
     1428                    e == GL_PRIMARY_COLOR_ARB ||
     1429                    e == GL_PREVIOUS_ARB)) {
     1430                t->unit[t->curTextureUnit].combineSourceRGB[stage] = e;
     1431            }
     1432            else if (g->extensions.ARB_texture_env_crossbar &&
     1433                            e >= GL_TEXTURE0_ARB &&
     1434                            e < GL_TEXTURE0_ARB + g->limits.maxTextureUnits) {
     1435                t->unit[t->curTextureUnit].combineSourceRGB[stage] = e;
     1436            }
     1437            else {
     1438                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1439                return;
     1440            }
     1441            break;
     1442        case GL_SOURCE0_ALPHA_ARB:
     1443        case GL_SOURCE1_ALPHA_ARB:
     1444        case GL_SOURCE2_ALPHA_ARB:
     1445            e = (GLenum) *param;
     1446            stage = pname - GL_SOURCE0_ALPHA_ARB;
     1447            if (g->extensions.ARB_texture_env_combine &&
     1448                    (e == GL_TEXTURE ||
     1449                    e == GL_CONSTANT_ARB ||
     1450                    e == GL_PRIMARY_COLOR_ARB ||
     1451                    e == GL_PREVIOUS_ARB)) {
     1452                t->unit[t->curTextureUnit].combineSourceA[stage] = e;
     1453            }
     1454            else if (g->extensions.ARB_texture_env_crossbar &&
     1455                            e >= GL_TEXTURE0_ARB &&
     1456                            e < GL_TEXTURE0_ARB + g->limits.maxTextureUnits) {
     1457                t->unit[t->curTextureUnit].combineSourceA[stage] = e;
     1458            }
     1459            else {
     1460                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1461                return;
     1462            }
     1463            break;
     1464        case GL_OPERAND0_RGB_ARB:
     1465        case GL_OPERAND1_RGB_ARB:
     1466        case GL_OPERAND2_RGB_ARB:
     1467            e = (GLenum) *param;
     1468            stage = pname - GL_OPERAND0_RGB_ARB;
     1469            if (g->extensions.ARB_texture_env_combine &&
     1470                    (e == GL_SRC_COLOR ||
     1471                    e == GL_ONE_MINUS_SRC_COLOR ||
     1472                    e == GL_SRC_ALPHA ||
     1473                    e == GL_ONE_MINUS_SRC_ALPHA)) {
     1474                t->unit[t->curTextureUnit].combineOperandRGB[stage] = e;
     1475            }
     1476            else {
     1477                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv");
     1478                return;
     1479            }
     1480            break;
     1481        case GL_OPERAND0_ALPHA_ARB:
     1482        case GL_OPERAND1_ALPHA_ARB:
     1483        case GL_OPERAND2_ALPHA_ARB:
     1484            e = (GLenum) *param;
     1485            stage = pname - GL_OPERAND0_ALPHA_ARB;
     1486            if (g->extensions.ARB_texture_env_combine &&
     1487                    (e == GL_SRC_ALPHA ||
     1488                    e == GL_ONE_MINUS_SRC_ALPHA)) {
     1489                t->unit[t->curTextureUnit].combineOperandA[stage] = e;
     1490            }
     1491            else {
     1492                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glTexEnvfv(param=0x%x)", e);
     1493                return;
     1494            }
     1495            break;
     1496        case GL_RGB_SCALE_ARB:
     1497            if (g->extensions.ARB_texture_env_combine &&
     1498                    (*param == 1.0 ||
     1499                    *param == 2.0 ||
     1500                    *param == 4.0)) {
     1501                t->unit[t->curTextureUnit].combineScaleRGB = *param;
     1502            }
     1503            else {
     1504                crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
     1505                return;
     1506            }
     1507            break;
     1508        case GL_ALPHA_SCALE:
     1509            if (g->extensions.ARB_texture_env_combine &&
     1510                    (*param == 1.0 ||
     1511                    *param == 2.0 ||
     1512                    *param == 4.0)) {
     1513                t->unit[t->curTextureUnit].combineScaleA = *param;
     1514            }
     1515            else {
     1516                crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glTexEnvfv");
     1517                return;
     1518            }
     1519        break;
    15201520#endif /* CR_ARB_texture_env_combine */
    15211521
    1522                 default:
    1523                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1524                                                 "glTexEnvfv: invalid pname: %d", pname);
    1525                         return;
    1526         }
    1527 
    1528         DIRTY(tb->envBit[t->curTextureUnit], g->neg_bitid);
    1529         DIRTY(tb->dirty, g->neg_bitid);
     1522        default:
     1523            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1524                        "glTexEnvfv: invalid pname: %d", pname);
     1525            return;
     1526    }
     1527
     1528    DIRTY(tb->envBit[t->curTextureUnit], g->neg_bitid);
     1529    DIRTY(tb->dirty, g->neg_bitid);
    15301530}
    15311531
     
    15341534crStateTexEnviv(GLenum target, GLenum pname, const GLint *param)
    15351535{
    1536         GLfloat f_param;
    1537         GLcolor f_color;
    1538 
    1539         switch (pname) {
    1540                 case GL_TEXTURE_ENV_MODE:
    1541                         f_param = (GLfloat) (*param);
    1542                         crStateTexEnvfv( target, pname, &f_param );
    1543                         break;
    1544                 case GL_TEXTURE_ENV_COLOR:
    1545                         f_color.r = ((GLfloat) param[0]) / CR_MAXINT;
    1546                         f_color.g = ((GLfloat) param[1]) / CR_MAXINT;
    1547                         f_color.b = ((GLfloat) param[2]) / CR_MAXINT;
    1548                         f_color.a = ((GLfloat) param[3]) / CR_MAXINT;
    1549                         crStateTexEnvfv( target, pname, (const GLfloat *) &f_color );
    1550                         break;
     1536    GLfloat f_param;
     1537    GLcolor f_color;
     1538
     1539    switch (pname) {
     1540        case GL_TEXTURE_ENV_MODE:
     1541            f_param = (GLfloat) (*param);
     1542            crStateTexEnvfv( target, pname, &f_param );
     1543            break;
     1544        case GL_TEXTURE_ENV_COLOR:
     1545            f_color.r = ((GLfloat) param[0]) / CR_MAXINT;
     1546            f_color.g = ((GLfloat) param[1]) / CR_MAXINT;
     1547            f_color.b = ((GLfloat) param[2]) / CR_MAXINT;
     1548            f_color.a = ((GLfloat) param[3]) / CR_MAXINT;
     1549            crStateTexEnvfv( target, pname, (const GLfloat *) &f_color );
     1550            break;
    15511551#ifdef CR_ARB_texture_env_combine
    1552                 case GL_COMBINE_RGB_ARB:
    1553                 case GL_COMBINE_ALPHA_EXT:
    1554                 case GL_SOURCE0_RGB_ARB:
    1555                 case GL_SOURCE1_RGB_ARB:
    1556                 case GL_SOURCE2_RGB_ARB:
    1557                 case GL_SOURCE0_ALPHA_ARB:
    1558                 case GL_SOURCE1_ALPHA_ARB:
    1559                 case GL_SOURCE2_ALPHA_ARB:
    1560                 case GL_OPERAND0_RGB_ARB:
    1561                 case GL_OPERAND1_RGB_ARB:
    1562                 case GL_OPERAND2_RGB_ARB:
    1563                 case GL_OPERAND0_ALPHA_ARB:
    1564                 case GL_OPERAND1_ALPHA_ARB:
    1565                 case GL_OPERAND2_ALPHA_ARB:
    1566                 case GL_RGB_SCALE_ARB:
    1567                 case GL_ALPHA_SCALE:
    1568                         f_param = (GLfloat) (*param);
    1569                         crStateTexEnvfv( target, pname, &f_param );
    1570                         break;
     1552        case GL_COMBINE_RGB_ARB:
     1553        case GL_COMBINE_ALPHA_EXT:
     1554        case GL_SOURCE0_RGB_ARB:
     1555        case GL_SOURCE1_RGB_ARB:
     1556        case GL_SOURCE2_RGB_ARB:
     1557        case GL_SOURCE0_ALPHA_ARB:
     1558        case GL_SOURCE1_ALPHA_ARB:
     1559        case GL_SOURCE2_ALPHA_ARB:
     1560        case GL_OPERAND0_RGB_ARB:
     1561        case GL_OPERAND1_RGB_ARB:
     1562        case GL_OPERAND2_RGB_ARB:
     1563        case GL_OPERAND0_ALPHA_ARB:
     1564        case GL_OPERAND1_ALPHA_ARB:
     1565        case GL_OPERAND2_ALPHA_ARB:
     1566        case GL_RGB_SCALE_ARB:
     1567        case GL_ALPHA_SCALE:
     1568            f_param = (GLfloat) (*param);
     1569            crStateTexEnvfv( target, pname, &f_param );
     1570            break;
    15711571#endif
    15721572#ifdef CR_EXT_texture_lod_bias
    1573                 case GL_TEXTURE_LOD_BIAS_EXT:
    1574                         f_param = (GLfloat) (*param);
    1575                         crStateTexEnvfv( target, pname, &f_param);
    1576                         break;
     1573        case GL_TEXTURE_LOD_BIAS_EXT:
     1574            f_param = (GLfloat) (*param);
     1575            crStateTexEnvfv( target, pname, &f_param);
     1576            break;
    15771577#endif
    15781578#ifdef CR_ARB_point_sprite
    1579                 case GL_COORD_REPLACE_ARB:
    1580                         f_param = (GLfloat) *param;
    1581                         crStateTexEnvfv( target, pname, &f_param);
    1582                         break;
    1583 #endif
    1584 
    1585                 default:
    1586                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1587                                                 "glTexEnvfv: invalid pname: %d", pname);
    1588                         return;
    1589         }
     1579        case GL_COORD_REPLACE_ARB:
     1580            f_param = (GLfloat) *param;
     1581            crStateTexEnvfv( target, pname, &f_param);
     1582            break;
     1583#endif
     1584
     1585        default:
     1586            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1587                        "glTexEnvfv: invalid pname: %d", pname);
     1588            return;
     1589    }
    15901590}
    15911591
     
    15941594crStateTexEnvf(GLenum target, GLenum pname, GLfloat param)
    15951595{
    1596         crStateTexEnvfv( target, pname, &param );
     1596    crStateTexEnvfv( target, pname, &param );
    15971597}
    15981598
     
    16011601crStateTexEnvi(GLenum target, GLenum pname, GLint param)
    16021602{
    1603         GLfloat f_param = (GLfloat) param;
    1604         crStateTexEnvfv( target, pname, &f_param );
     1603    GLfloat f_param = (GLfloat) param;
     1604    crStateTexEnvfv( target, pname, &f_param );
    16051605}
    16061606
     
    16091609crStateGetTexEnvfv(GLenum target, GLenum pname, GLfloat *param)
    16101610{
    1611         CRContext *g = GetCurrentContext();
    1612         CRTextureState *t = &(g->texture);
    1613 
    1614         if (g->current.inBeginEnd)
    1615         {
    1616                 crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
    1617                                         "glGetTexEnvfv called in begin/end");
    1618                 return;
    1619         }
     1611    CRContext *g = GetCurrentContext();
     1612    CRTextureState *t = &(g->texture);
     1613
     1614    if (g->current.inBeginEnd)
     1615    {
     1616        crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
     1617                    "glGetTexEnvfv called in begin/end");
     1618        return;
     1619    }
    16201620
    16211621#if CR_EXT_texture_lod_bias
    1622         if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
    1623                 if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
    1624                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    1625                 }
    1626                 else {
    1627                         *param = t->unit[t->curTextureUnit].lodBias;
    1628                 }
    1629                 return;
    1630         }
    1631         else
     1622    if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
     1623        if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
     1624            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     1625        }
     1626        else {
     1627            *param = t->unit[t->curTextureUnit].lodBias;
     1628        }
     1629        return;
     1630    }
     1631    else
    16321632#endif
    16331633#if CR_ARB_point_sprite
    1634         if (target == GL_POINT_SPRITE_ARB) {
    1635                 if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
    1636                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    1637                 }
    1638                 else {
    1639                         *param = (GLfloat) g->point.coordReplacement[t->curTextureUnit];
    1640                 }
    1641                 return;
    1642         }
    1643         else
    1644 #endif
    1645         if (target != GL_TEXTURE_ENV)
    1646         {
    1647                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1648                                         "glGetTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
    1649                 return;
    1650         }
    1651 
    1652         switch (pname) {
    1653                 case GL_TEXTURE_ENV_MODE:
    1654                         *param = (GLfloat) t->unit[t->curTextureUnit].envMode;
    1655                         break;
    1656                 case GL_TEXTURE_ENV_COLOR:
    1657                         param[0] = t->unit[t->curTextureUnit].envColor.r;
    1658                         param[1] = t->unit[t->curTextureUnit].envColor.g;
    1659                         param[2] = t->unit[t->curTextureUnit].envColor.b;
    1660                         param[3] = t->unit[t->curTextureUnit].envColor.a;
    1661                         break;
    1662                 case GL_COMBINE_RGB_ARB:
    1663                         if (g->extensions.ARB_texture_env_combine) {
    1664                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineModeRGB;
    1665                         }
    1666                         else {
    1667                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1668                                 return;
    1669                         }
    1670                         break;
    1671                 case GL_COMBINE_ALPHA_ARB:
    1672                         if (g->extensions.ARB_texture_env_combine) {
    1673                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineModeA;
    1674                         }
    1675                         else {
    1676                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1677                                 return;
    1678                         }
    1679                         break;
    1680                 case GL_SOURCE0_RGB_ARB:
    1681                         if (g->extensions.ARB_texture_env_combine) {
    1682                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[0];
    1683                         }
    1684                         else {
    1685                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1686                                 return;
    1687                         }
    1688                         break;
    1689                 case GL_SOURCE1_RGB_ARB:
    1690                         if (g->extensions.ARB_texture_env_combine) {
    1691                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[1];
    1692                         }
    1693                         else {
    1694                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1695                                 return;
    1696                         }
    1697                         break;
    1698                 case GL_SOURCE2_RGB_ARB:
    1699                         if (g->extensions.ARB_texture_env_combine) {
    1700                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[2];
    1701                         }
    1702                         else {
    1703                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1704                                 return;
    1705                         }
    1706                         break;
    1707                 case GL_SOURCE0_ALPHA_ARB:
    1708                         if (g->extensions.ARB_texture_env_combine) {
    1709                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[0];
    1710                         }
    1711                         else {
    1712                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1713                                 return;
    1714                         }
    1715                         break;
    1716                 case GL_SOURCE1_ALPHA_ARB:
    1717                         if (g->extensions.ARB_texture_env_combine) {
    1718                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[1];
    1719                         }
    1720                         else {
    1721                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1722                                 return;
    1723                         }
    1724                         break;
    1725                 case GL_SOURCE2_ALPHA_ARB:
    1726                         if (g->extensions.ARB_texture_env_combine) {
    1727                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[2];
    1728                         }
    1729                         else {
    1730                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1731                                 return;
    1732                         }
    1733                         break;
    1734                 case GL_OPERAND0_RGB_ARB:
    1735                         if (g->extensions.ARB_texture_env_combine) {
    1736                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[0];
    1737                         }
    1738                         else {
    1739                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1740                                 return;
    1741                         }
    1742                         break;
    1743                 case GL_OPERAND1_RGB_ARB:
    1744                         if (g->extensions.ARB_texture_env_combine) {
    1745                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[1];
    1746                         }
    1747                         else {
    1748                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1749                                 return;
    1750                         }
    1751                         break;
    1752                 case GL_OPERAND2_RGB_ARB:
    1753                         if (g->extensions.ARB_texture_env_combine) {
    1754                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[2];
    1755                         }
    1756                         else {
    1757                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1758                                 return;
    1759                         }
    1760                         break;
    1761                 case GL_OPERAND0_ALPHA_ARB:
    1762                         if (g->extensions.ARB_texture_env_combine) {
    1763                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[0];
    1764                         }
    1765                         else {
    1766                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1767                                 return;
    1768                         }
    1769                         break;
    1770                 case GL_OPERAND1_ALPHA_ARB:
    1771                         if (g->extensions.ARB_texture_env_combine) {
    1772                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[1];
    1773                         }
    1774                         else {
    1775                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1776                                 return;
    1777                         }
    1778                         break;
    1779                 case GL_OPERAND2_ALPHA_ARB:
    1780                         if (g->extensions.ARB_texture_env_combine) {
    1781                                 *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[2];
    1782                         }
    1783                         else {
    1784                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1785                                 return;
    1786                         }
    1787                         break;
    1788                 case GL_RGB_SCALE_ARB:
    1789                         if (g->extensions.ARB_texture_env_combine) {
    1790                                 *param = t->unit[t->curTextureUnit].combineScaleRGB;
    1791                         }
    1792                         else {
    1793                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1794                                 return;
    1795                         }
    1796                         break;
    1797                 case GL_ALPHA_SCALE:
    1798                         if (g->extensions.ARB_texture_env_combine) {
    1799                                 *param = t->unit[t->curTextureUnit].combineScaleA;
    1800                         }
    1801                         else {
    1802                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
    1803                                 return;
    1804                         }
    1805                         break;
    1806                 default:
    1807                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1808                                                 "glGetTexEnvfv: invalid pname: %d", pname);
    1809                         return;
    1810         }
     1634    if (target == GL_POINT_SPRITE_ARB) {
     1635        if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
     1636            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     1637        }
     1638        else {
     1639            *param = (GLfloat) g->point.coordReplacement[t->curTextureUnit];
     1640        }
     1641        return;
     1642    }
     1643    else
     1644#endif
     1645    if (target != GL_TEXTURE_ENV)
     1646    {
     1647        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1648                    "glGetTexEnvfv: target != GL_TEXTURE_ENV: %d", target);
     1649        return;
     1650    }
     1651
     1652    switch (pname) {
     1653        case GL_TEXTURE_ENV_MODE:
     1654            *param = (GLfloat) t->unit[t->curTextureUnit].envMode;
     1655            break;
     1656        case GL_TEXTURE_ENV_COLOR:
     1657            param[0] = t->unit[t->curTextureUnit].envColor.r;
     1658            param[1] = t->unit[t->curTextureUnit].envColor.g;
     1659            param[2] = t->unit[t->curTextureUnit].envColor.b;
     1660            param[3] = t->unit[t->curTextureUnit].envColor.a;
     1661            break;
     1662        case GL_COMBINE_RGB_ARB:
     1663            if (g->extensions.ARB_texture_env_combine) {
     1664                *param = (GLfloat) t->unit[t->curTextureUnit].combineModeRGB;
     1665            }
     1666            else {
     1667                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1668                return;
     1669            }
     1670            break;
     1671        case GL_COMBINE_ALPHA_ARB:
     1672            if (g->extensions.ARB_texture_env_combine) {
     1673                *param = (GLfloat) t->unit[t->curTextureUnit].combineModeA;
     1674            }
     1675            else {
     1676                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1677                return;
     1678            }
     1679            break;
     1680        case GL_SOURCE0_RGB_ARB:
     1681            if (g->extensions.ARB_texture_env_combine) {
     1682                *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[0];
     1683            }
     1684            else {
     1685                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1686                return;
     1687            }
     1688            break;
     1689        case GL_SOURCE1_RGB_ARB:
     1690            if (g->extensions.ARB_texture_env_combine) {
     1691                *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[1];
     1692            }
     1693            else {
     1694                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1695                return;
     1696            }
     1697            break;
     1698        case GL_SOURCE2_RGB_ARB:
     1699            if (g->extensions.ARB_texture_env_combine) {
     1700                *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceRGB[2];
     1701            }
     1702            else {
     1703                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1704                return;
     1705            }
     1706            break;
     1707        case GL_SOURCE0_ALPHA_ARB:
     1708            if (g->extensions.ARB_texture_env_combine) {
     1709                *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[0];
     1710            }
     1711            else {
     1712                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1713                return;
     1714            }
     1715            break;
     1716        case GL_SOURCE1_ALPHA_ARB:
     1717            if (g->extensions.ARB_texture_env_combine) {
     1718                *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[1];
     1719            }
     1720            else {
     1721                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1722                return;
     1723            }
     1724            break;
     1725        case GL_SOURCE2_ALPHA_ARB:
     1726            if (g->extensions.ARB_texture_env_combine) {
     1727                *param = (GLfloat) t->unit[t->curTextureUnit].combineSourceA[2];
     1728            }
     1729            else {
     1730                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1731                return;
     1732            }
     1733            break;
     1734        case GL_OPERAND0_RGB_ARB:
     1735            if (g->extensions.ARB_texture_env_combine) {
     1736                *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[0];
     1737            }
     1738            else {
     1739                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1740                return;
     1741            }
     1742            break;
     1743        case GL_OPERAND1_RGB_ARB:
     1744            if (g->extensions.ARB_texture_env_combine) {
     1745                *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[1];
     1746            }
     1747            else {
     1748                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1749                return;
     1750            }
     1751            break;
     1752        case GL_OPERAND2_RGB_ARB:
     1753            if (g->extensions.ARB_texture_env_combine) {
     1754                *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandRGB[2];
     1755            }
     1756            else {
     1757                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1758                return;
     1759            }
     1760            break;
     1761        case GL_OPERAND0_ALPHA_ARB:
     1762            if (g->extensions.ARB_texture_env_combine) {
     1763                *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[0];
     1764            }
     1765            else {
     1766                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1767                return;
     1768            }
     1769            break;
     1770        case GL_OPERAND1_ALPHA_ARB:
     1771            if (g->extensions.ARB_texture_env_combine) {
     1772                *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[1];
     1773            }
     1774            else {
     1775                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1776                return;
     1777            }
     1778            break;
     1779        case GL_OPERAND2_ALPHA_ARB:
     1780            if (g->extensions.ARB_texture_env_combine) {
     1781                *param = (GLfloat) t->unit[t->curTextureUnit].combineOperandA[2];
     1782            }
     1783            else {
     1784                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1785                return;
     1786            }
     1787            break;
     1788        case GL_RGB_SCALE_ARB:
     1789            if (g->extensions.ARB_texture_env_combine) {
     1790                *param = t->unit[t->curTextureUnit].combineScaleRGB;
     1791            }
     1792            else {
     1793                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1794                return;
     1795            }
     1796            break;
     1797        case GL_ALPHA_SCALE:
     1798            if (g->extensions.ARB_texture_env_combine) {
     1799                *param = t->unit[t->curTextureUnit].combineScaleA;
     1800            }
     1801            else {
     1802                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
     1803                return;
     1804            }
     1805            break;
     1806        default:
     1807            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1808                        "glGetTexEnvfv: invalid pname: %d", pname);
     1809            return;
     1810    }
    18111811}
    18121812
     
    18151815crStateGetTexEnviv(GLenum target, GLenum pname, GLint *param)
    18161816{
    1817         CRContext *g = GetCurrentContext();
    1818         CRTextureState *t = &(g->texture);
    1819 
    1820         if (g->current.inBeginEnd)
    1821         {
    1822                 crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
    1823                                         "glGetTexEnviv called in begin/end");
    1824                 return;
    1825         }
     1817    CRContext *g = GetCurrentContext();
     1818    CRTextureState *t = &(g->texture);
     1819
     1820    if (g->current.inBeginEnd)
     1821    {
     1822        crStateError(__LINE__, __FILE__,GL_INVALID_OPERATION,
     1823                    "glGetTexEnviv called in begin/end");
     1824        return;
     1825    }
    18261826
    18271827#if CR_EXT_texture_lod_bias
    1828         if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
    1829                 if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
    1830                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    1831                 }
    1832                 else {
    1833                         *param = (GLint) t->unit[t->curTextureUnit].lodBias;
    1834                 }
    1835                 return;
    1836         }
    1837         else
     1828    if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
     1829        if (!g->extensions.EXT_texture_lod_bias || pname != GL_TEXTURE_LOD_BIAS_EXT) {
     1830            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     1831        }
     1832        else {
     1833            *param = (GLint) t->unit[t->curTextureUnit].lodBias;
     1834        }
     1835        return;
     1836    }
     1837    else
    18381838#endif
    18391839#if CR_ARB_point_sprite
    1840         if (target == GL_POINT_SPRITE_ARB) {
    1841                 if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
    1842                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
    1843                 }
    1844                 else {
    1845                         *param = (GLint) g->point.coordReplacement[t->curTextureUnit];
    1846                 }
    1847                 return;
    1848         }
    1849         else
    1850 #endif
    1851         if (target != GL_TEXTURE_ENV)
    1852         {
    1853                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    1854                                         "glGetTexEnviv: target != GL_TEXTURE_ENV: %d", target);
    1855                 return;
    1856         }
    1857 
    1858         switch (pname) {
    1859                 case GL_TEXTURE_ENV_MODE:
    1860                         *param = (GLint) t->unit[t->curTextureUnit].envMode;
    1861                         break;
    1862                 case GL_TEXTURE_ENV_COLOR:
    1863                         param[0] = (GLint) (t->unit[t->curTextureUnit].envColor.r * CR_MAXINT);
    1864                         param[1] = (GLint) (t->unit[t->curTextureUnit].envColor.g * CR_MAXINT);
    1865                         param[2] = (GLint) (t->unit[t->curTextureUnit].envColor.b * CR_MAXINT);
    1866                         param[3] = (GLint) (t->unit[t->curTextureUnit].envColor.a * CR_MAXINT);
    1867                         break;
    1868                 case GL_COMBINE_RGB_ARB:
    1869                         if (g->extensions.ARB_texture_env_combine) {
    1870                                 *param = (GLint) t->unit[t->curTextureUnit].combineModeRGB;
    1871                         }
    1872                         else {
    1873                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1874                                 return;
    1875                         }
    1876                         break;
    1877                 case GL_COMBINE_ALPHA_ARB:
    1878                         if (g->extensions.ARB_texture_env_combine) {
    1879                                 *param = (GLint) t->unit[t->curTextureUnit].combineModeA;
    1880                         }
    1881                         else {
    1882                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1883                                 return;
    1884                         }
    1885                         break;
    1886                 case GL_SOURCE0_RGB_ARB:
    1887                         if (g->extensions.ARB_texture_env_combine) {
    1888                                 *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[0];
    1889                         }
    1890                         else {
    1891                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1892                                 return;
    1893                         }
    1894                         break;
    1895                 case GL_SOURCE1_RGB_ARB:
    1896                         if (g->extensions.ARB_texture_env_combine) {
    1897                                 *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[1];
    1898                         }
    1899                         else {
    1900                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1901                                 return;
    1902                         }
    1903                         break;
    1904                 case GL_SOURCE2_RGB_ARB:
    1905                         if (g->extensions.ARB_texture_env_combine) {
    1906                                 *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[2];
    1907                         }
    1908                         else {
    1909                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1910                                 return;
    1911                         }
    1912                         break;
    1913                 case GL_SOURCE0_ALPHA_ARB:
    1914                         if (g->extensions.ARB_texture_env_combine) {
    1915                                 *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[0];
    1916                         }
    1917                         else {
    1918                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1919                                 return;
    1920                         }
    1921                         break;
    1922                 case GL_SOURCE1_ALPHA_ARB:
    1923                         if (g->extensions.ARB_texture_env_combine) {
    1924                                 *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[1];
    1925                         }
    1926                         else {
    1927                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1928                                 return;
    1929                         }
    1930                         break;
    1931                 case GL_SOURCE2_ALPHA_ARB:
    1932                         if (g->extensions.ARB_texture_env_combine) {
    1933                                 *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[2];
    1934                         }
    1935                         else {
    1936                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1937                                 return;
    1938                         }
    1939                         break;
    1940                 case GL_OPERAND0_RGB_ARB:
    1941                         if (g->extensions.ARB_texture_env_combine) {
    1942                                 *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[0];
    1943                         }
    1944                         else {
    1945                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1946                                 return;
    1947                         }
    1948                         break;
    1949                 case GL_OPERAND1_RGB_ARB:
    1950                         if (g->extensions.ARB_texture_env_combine) {
    1951                                 *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[1];
    1952                         }
    1953                         else {
    1954                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1955                                 return;
    1956                         }
    1957                         break;
    1958                 case GL_OPERAND2_RGB_ARB:
    1959                         if (g->extensions.ARB_texture_env_combine) {
    1960                                 *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[2];
    1961                         }
    1962                         else {
    1963                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1964                                 return;
    1965                         }
    1966                         break;
    1967                 case GL_OPERAND0_ALPHA_ARB:
    1968                         if (g->extensions.ARB_texture_env_combine) {
    1969                                 *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[0];
    1970                         }
    1971                         else {
    1972                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1973                                 return;
    1974                         }
    1975                         break;
    1976                 case GL_OPERAND1_ALPHA_ARB:
    1977                         if (g->extensions.ARB_texture_env_combine) {
    1978                                 *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[1];
    1979                         }
    1980                         else {
    1981                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1982                                 return;
    1983                         }
    1984                         break;
    1985                 case GL_OPERAND2_ALPHA_ARB:
    1986                         if (g->extensions.ARB_texture_env_combine) {
    1987                                 *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[2];
    1988                         }
    1989                         else {
    1990                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    1991                                 return;
    1992                         }
    1993                         break;
    1994                 case GL_RGB_SCALE_ARB:
    1995                         if (g->extensions.ARB_texture_env_combine) {
    1996                                 *param = (GLint) t->unit[t->curTextureUnit].combineScaleRGB;
    1997                         }
    1998                         else {
    1999                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    2000                                 return;
    2001                         }
    2002                         break;
    2003                 case GL_ALPHA_SCALE:
    2004                         if (g->extensions.ARB_texture_env_combine) {
    2005                                 *param = (GLint) t->unit[t->curTextureUnit].combineScaleA;
    2006                         }
    2007                         else {
    2008                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
    2009                                 return;
    2010                         }
    2011                         break;
    2012                 default:
    2013                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2014                                                 "glGetTexEnviv: invalid pname: %d", pname);
    2015                         return;
    2016         }
     1840    if (target == GL_POINT_SPRITE_ARB) {
     1841        if (!g->extensions.ARB_point_sprite || pname != GL_COORD_REPLACE_ARB) {
     1842            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnv");
     1843        }
     1844        else {
     1845            *param = (GLint) g->point.coordReplacement[t->curTextureUnit];
     1846        }
     1847        return;
     1848    }
     1849    else
     1850#endif
     1851    if (target != GL_TEXTURE_ENV)
     1852    {
     1853        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     1854                    "glGetTexEnviv: target != GL_TEXTURE_ENV: %d", target);
     1855        return;
     1856    }
     1857
     1858    switch (pname) {
     1859        case GL_TEXTURE_ENV_MODE:
     1860            *param = (GLint) t->unit[t->curTextureUnit].envMode;
     1861            break;
     1862        case GL_TEXTURE_ENV_COLOR:
     1863            param[0] = (GLint) (t->unit[t->curTextureUnit].envColor.r * CR_MAXINT);
     1864            param[1] = (GLint) (t->unit[t->curTextureUnit].envColor.g * CR_MAXINT);
     1865            param[2] = (GLint) (t->unit[t->curTextureUnit].envColor.b * CR_MAXINT);
     1866            param[3] = (GLint) (t->unit[t->curTextureUnit].envColor.a * CR_MAXINT);
     1867            break;
     1868        case GL_COMBINE_RGB_ARB:
     1869            if (g->extensions.ARB_texture_env_combine) {
     1870                *param = (GLint) t->unit[t->curTextureUnit].combineModeRGB;
     1871            }
     1872            else {
     1873                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1874                return;
     1875            }
     1876            break;
     1877        case GL_COMBINE_ALPHA_ARB:
     1878            if (g->extensions.ARB_texture_env_combine) {
     1879                *param = (GLint) t->unit[t->curTextureUnit].combineModeA;
     1880            }
     1881            else {
     1882                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1883                return;
     1884            }
     1885            break;
     1886        case GL_SOURCE0_RGB_ARB:
     1887            if (g->extensions.ARB_texture_env_combine) {
     1888                *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[0];
     1889            }
     1890            else {
     1891                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1892                return;
     1893            }
     1894            break;
     1895        case GL_SOURCE1_RGB_ARB:
     1896            if (g->extensions.ARB_texture_env_combine) {
     1897                *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[1];
     1898            }
     1899            else {
     1900                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1901                return;
     1902            }
     1903            break;
     1904        case GL_SOURCE2_RGB_ARB:
     1905            if (g->extensions.ARB_texture_env_combine) {
     1906                *param = (GLint) t->unit[t->curTextureUnit].combineSourceRGB[2];
     1907            }
     1908            else {
     1909                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1910                return;
     1911            }
     1912            break;
     1913        case GL_SOURCE0_ALPHA_ARB:
     1914            if (g->extensions.ARB_texture_env_combine) {
     1915                *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[0];
     1916            }
     1917            else {
     1918                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1919                return;
     1920            }
     1921            break;
     1922        case GL_SOURCE1_ALPHA_ARB:
     1923            if (g->extensions.ARB_texture_env_combine) {
     1924                *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[1];
     1925            }
     1926            else {
     1927                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1928                return;
     1929            }
     1930            break;
     1931        case GL_SOURCE2_ALPHA_ARB:
     1932            if (g->extensions.ARB_texture_env_combine) {
     1933                *param = (GLint) t->unit[t->curTextureUnit].combineSourceA[2];
     1934            }
     1935            else {
     1936                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1937                return;
     1938            }
     1939            break;
     1940        case GL_OPERAND0_RGB_ARB:
     1941            if (g->extensions.ARB_texture_env_combine) {
     1942                *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[0];
     1943            }
     1944            else {
     1945                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1946                return;
     1947            }
     1948            break;
     1949        case GL_OPERAND1_RGB_ARB:
     1950            if (g->extensions.ARB_texture_env_combine) {
     1951                *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[1];
     1952            }
     1953            else {
     1954                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1955                return;
     1956            }
     1957            break;
     1958        case GL_OPERAND2_RGB_ARB:
     1959            if (g->extensions.ARB_texture_env_combine) {
     1960                *param = (GLint) t->unit[t->curTextureUnit].combineOperandRGB[2];
     1961            }
     1962            else {
     1963                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1964                return;
     1965            }
     1966            break;
     1967        case GL_OPERAND0_ALPHA_ARB:
     1968            if (g->extensions.ARB_texture_env_combine) {
     1969                *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[0];
     1970            }
     1971            else {
     1972                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1973                return;
     1974            }
     1975            break;
     1976        case GL_OPERAND1_ALPHA_ARB:
     1977            if (g->extensions.ARB_texture_env_combine) {
     1978                *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[1];
     1979            }
     1980            else {
     1981                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1982                return;
     1983            }
     1984            break;
     1985        case GL_OPERAND2_ALPHA_ARB:
     1986            if (g->extensions.ARB_texture_env_combine) {
     1987                *param = (GLint) t->unit[t->curTextureUnit].combineOperandA[2];
     1988            }
     1989            else {
     1990                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     1991                return;
     1992            }
     1993            break;
     1994        case GL_RGB_SCALE_ARB:
     1995            if (g->extensions.ARB_texture_env_combine) {
     1996                *param = (GLint) t->unit[t->curTextureUnit].combineScaleRGB;
     1997            }
     1998            else {
     1999                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2000                return;
     2001            }
     2002            break;
     2003        case GL_ALPHA_SCALE:
     2004            if (g->extensions.ARB_texture_env_combine) {
     2005                *param = (GLint) t->unit[t->curTextureUnit].combineScaleA;
     2006            }
     2007            else {
     2008                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
     2009                return;
     2010            }
     2011            break;
     2012        default:
     2013            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2014                        "glGetTexEnviv: invalid pname: %d", pname);
     2015            return;
     2016    }
    20172017}
    20182018
     
    20212021crStateTexGendv(GLenum coord, GLenum pname, const GLdouble *param)
    20222022{
    2023         CRContext *g = GetCurrentContext();
    2024         CRTextureState *t = &(g->texture);
    2025         CRTransformState *trans = &(g->transform);
    2026         GLvectorf v;
    2027         GLenum e;
    2028         CRmatrix inv;
    2029         CRStateBits *sb = GetCurrentBits();
    2030         CRTextureBits *tb = &(sb->texture);
    2031 
    2032         FLUSH();
    2033 
    2034         if (g->current.inBeginEnd)
    2035         {
    2036                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2037                                         "glTexGen called in begin/end");
    2038                 return;
    2039         }
    2040 
    2041         switch (coord)
    2042         {
    2043                 case GL_S:
    2044                         switch (pname)
    2045                         {
    2046                                 case GL_TEXTURE_GEN_MODE:
    2047                                         e = (GLenum) *param;
    2048                                         if (e == GL_OBJECT_LINEAR ||
    2049                                                 e == GL_EYE_LINEAR ||
    2050                                                 e == GL_SPHERE_MAP
     2023    CRContext *g = GetCurrentContext();
     2024    CRTextureState *t = &(g->texture);
     2025    CRTransformState *trans = &(g->transform);
     2026    GLvectorf v;
     2027    GLenum e;
     2028    CRmatrix inv;
     2029    CRStateBits *sb = GetCurrentBits();
     2030    CRTextureBits *tb = &(sb->texture);
     2031
     2032    FLUSH();
     2033
     2034    if (g->current.inBeginEnd)
     2035    {
     2036        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2037                    "glTexGen called in begin/end");
     2038        return;
     2039    }
     2040
     2041    switch (coord)
     2042    {
     2043        case GL_S:
     2044            switch (pname)
     2045            {
     2046                case GL_TEXTURE_GEN_MODE:
     2047                    e = (GLenum) *param;
     2048                    if (e == GL_OBJECT_LINEAR ||
     2049                        e == GL_EYE_LINEAR ||
     2050                        e == GL_SPHERE_MAP
    20512051#if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
    2052                                                 || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
    2053                                                         && g->extensions.ARB_texture_cube_map)
    2054 #endif
    2055                                         ) {
    2056                                                 t->unit[t->curTextureUnit].gen.s = e;
    2057                                                 DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
    2058                                                 DIRTY(tb->dirty, g->neg_bitid);
    2059                                         }
    2060                                         else {
    2061                                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2062                                                         "glTexGendv called with bad param: %lf", *param);
    2063                                                 return;
    2064                                         }
    2065                                         break;
    2066                                 case GL_OBJECT_PLANE:
    2067                                         v.x = (GLfloat) param[0];
    2068                                         v.y = (GLfloat) param[1];
    2069                                         v.z = (GLfloat) param[2];
    2070                                         v.w = (GLfloat) param[3];
    2071                                         t->unit[t->curTextureUnit].objSCoeff = v;
    2072                                         DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
    2073                                         DIRTY(tb->dirty, g->neg_bitid);
    2074                                         break;
    2075                                 case GL_EYE_PLANE:
    2076                                         v.x = (GLfloat) param[0];
    2077                                         v.y = (GLfloat) param[1];
    2078                                         v.z = (GLfloat) param[2];
    2079                                         v.w = (GLfloat) param[3];
    2080                                         crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
    2081                                         crStateTransformXformPointMatrixf(&inv, &v);
    2082                                         t->unit[t->curTextureUnit].eyeSCoeff = v;
    2083                                         DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
    2084                                         DIRTY(tb->dirty, g->neg_bitid);
    2085                                         break;
    2086                                 default:
    2087                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2088                                                                 "glTexGendv called with bogus pname: %d", pname);
    2089                                         return;
    2090                         }
    2091                         break;
    2092                 case GL_T:
    2093                         switch (pname) {
    2094                                 case GL_TEXTURE_GEN_MODE:
    2095                                         e = (GLenum) *param;
    2096                                         if (e == GL_OBJECT_LINEAR ||
    2097                                                 e == GL_EYE_LINEAR ||
    2098                                                 e == GL_SPHERE_MAP
     2052                        || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
     2053                            && g->extensions.ARB_texture_cube_map)
     2054#endif
     2055                    ) {
     2056                        t->unit[t->curTextureUnit].gen.s = e;
     2057                        DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
     2058                        DIRTY(tb->dirty, g->neg_bitid);
     2059                    }
     2060                    else {
     2061                        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2062                            "glTexGendv called with bad param: %lf", *param);
     2063                        return;
     2064                    }
     2065                    break;
     2066                case GL_OBJECT_PLANE:
     2067                    v.x = (GLfloat) param[0];
     2068                    v.y = (GLfloat) param[1];
     2069                    v.z = (GLfloat) param[2];
     2070                    v.w = (GLfloat) param[3];
     2071                    t->unit[t->curTextureUnit].objSCoeff = v;
     2072                    DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
     2073                    DIRTY(tb->dirty, g->neg_bitid);
     2074                    break;
     2075                case GL_EYE_PLANE:
     2076                    v.x = (GLfloat) param[0];
     2077                    v.y = (GLfloat) param[1];
     2078                    v.z = (GLfloat) param[2];
     2079                    v.w = (GLfloat) param[3];
     2080                    crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
     2081                    crStateTransformXformPointMatrixf(&inv, &v);
     2082                    t->unit[t->curTextureUnit].eyeSCoeff = v;
     2083                    DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
     2084                    DIRTY(tb->dirty, g->neg_bitid);
     2085                    break;
     2086                default:
     2087                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2088                                "glTexGendv called with bogus pname: %d", pname);
     2089                    return;
     2090            }
     2091            break;
     2092        case GL_T:
     2093            switch (pname) {
     2094                case GL_TEXTURE_GEN_MODE:
     2095                    e = (GLenum) *param;
     2096                    if (e == GL_OBJECT_LINEAR ||
     2097                        e == GL_EYE_LINEAR ||
     2098                        e == GL_SPHERE_MAP
    20992099#if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
    2100                                                 || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
    2101                                                         && g->extensions.ARB_texture_cube_map)
    2102 #endif
    2103                                         ) {
    2104                                                 t->unit[t->curTextureUnit].gen.t = e;
    2105                                                 DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
    2106                                                 DIRTY(tb->dirty, g->neg_bitid);
    2107                                         }
    2108                                         else {
    2109                                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2110                                                         "glTexGendv called with bad param: %lf", *param);
    2111                                                 return;
    2112                                         }
    2113                                         break;
    2114                                 case GL_OBJECT_PLANE:
    2115                                         v.x = (GLfloat) param[0];
    2116                                         v.y = (GLfloat) param[1];
    2117                                         v.z = (GLfloat) param[2];
    2118                                         v.w = (GLfloat) param[3];
    2119                                         t->unit[t->curTextureUnit].objTCoeff = v;
    2120                                         DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
    2121                                         DIRTY(tb->dirty, g->neg_bitid);
    2122                                         break;
    2123                                 case GL_EYE_PLANE:
    2124                                         v.x = (GLfloat) param[0];
    2125                                         v.y = (GLfloat) param[1];
    2126                                         v.z = (GLfloat) param[2];
    2127                                         v.w = (GLfloat) param[3];
    2128                                         crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
    2129                                         crStateTransformXformPointMatrixf(&inv, &v);
    2130                                         t->unit[t->curTextureUnit].eyeTCoeff = v;
    2131                                         DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
    2132                                         DIRTY(tb->dirty, g->neg_bitid);
    2133                                         break;
    2134                                 default:
    2135                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2136                                                                 "glTexGen called with bogus pname: %d", pname);
    2137                                         return;
    2138                         }
    2139                         break;
    2140                 case GL_R:
    2141                         switch (pname) {
    2142                                 case GL_TEXTURE_GEN_MODE:
    2143                                         e = (GLenum) *param;
    2144                                         if (e == GL_OBJECT_LINEAR ||
    2145                                                 e == GL_EYE_LINEAR ||
    2146                                                 e == GL_SPHERE_MAP
     2100                        || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
     2101                            && g->extensions.ARB_texture_cube_map)
     2102#endif
     2103                    ) {
     2104                        t->unit[t->curTextureUnit].gen.t = e;
     2105                        DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
     2106                        DIRTY(tb->dirty, g->neg_bitid);
     2107                    }
     2108                    else {
     2109                        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2110                            "glTexGendv called with bad param: %lf", *param);
     2111                        return;
     2112                    }
     2113                    break;
     2114                case GL_OBJECT_PLANE:
     2115                    v.x = (GLfloat) param[0];
     2116                    v.y = (GLfloat) param[1];
     2117                    v.z = (GLfloat) param[2];
     2118                    v.w = (GLfloat) param[3];
     2119                    t->unit[t->curTextureUnit].objTCoeff = v;
     2120                    DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
     2121                    DIRTY(tb->dirty, g->neg_bitid);
     2122                    break;
     2123                case GL_EYE_PLANE:
     2124                    v.x = (GLfloat) param[0];
     2125                    v.y = (GLfloat) param[1];
     2126                    v.z = (GLfloat) param[2];
     2127                    v.w = (GLfloat) param[3];
     2128                    crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
     2129                    crStateTransformXformPointMatrixf(&inv, &v);
     2130                    t->unit[t->curTextureUnit].eyeTCoeff = v;
     2131                    DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
     2132                    DIRTY(tb->dirty, g->neg_bitid);
     2133                    break;
     2134                default:
     2135                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2136                                "glTexGen called with bogus pname: %d", pname);
     2137                    return;
     2138            }
     2139            break;
     2140        case GL_R:
     2141            switch (pname) {
     2142                case GL_TEXTURE_GEN_MODE:
     2143                    e = (GLenum) *param;
     2144                    if (e == GL_OBJECT_LINEAR ||
     2145                        e == GL_EYE_LINEAR ||
     2146                        e == GL_SPHERE_MAP
    21472147#if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
    2148                                                 || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
    2149                                                         && g->extensions.ARB_texture_cube_map)
    2150 #endif
    2151                                         ) {
    2152                                                 t->unit[t->curTextureUnit].gen.r = e;
    2153                                                 DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
    2154                                                 DIRTY(tb->dirty, g->neg_bitid);
    2155                                         }
    2156                                         else {
    2157                                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2158                                                         "glTexGen called with bad param: %lf", *param);
    2159                                                 return;
    2160                                         }
    2161                                         break;
    2162                                 case GL_OBJECT_PLANE:
    2163                                         v.x = (GLfloat) param[0];
    2164                                         v.y = (GLfloat) param[1];
    2165                                         v.z = (GLfloat) param[2];
    2166                                         v.w = (GLfloat) param[3];
    2167                                         t->unit[t->curTextureUnit].objRCoeff = v;
    2168                                         DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
    2169                                         DIRTY(tb->dirty, g->neg_bitid);
    2170                                         break;
    2171                                 case GL_EYE_PLANE:
    2172                                         v.x = (GLfloat) param[0];
    2173                                         v.y = (GLfloat) param[1];
    2174                                         v.z = (GLfloat) param[2];
    2175                                         v.w = (GLfloat) param[3];
    2176                                         crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
    2177                                         crStateTransformXformPointMatrixf(&inv, &v);
    2178                                         t->unit[t->curTextureUnit].eyeRCoeff = v;
    2179                                         DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
    2180                                         DIRTY(tb->dirty, g->neg_bitid);
    2181                                         break;
    2182                                 default:
    2183                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2184                                                                 "glTexGen called with bogus pname: %d", pname);
    2185                                         return;
    2186                         }
    2187                         break;
    2188                 case GL_Q:
    2189                         switch (pname) {
    2190                                 case GL_TEXTURE_GEN_MODE:
    2191                                         e = (GLenum) *param;
    2192                                         if (e == GL_OBJECT_LINEAR ||
    2193                                                 e == GL_EYE_LINEAR ||
    2194                                                 e == GL_SPHERE_MAP
     2148                        || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
     2149                            && g->extensions.ARB_texture_cube_map)
     2150#endif
     2151                    ) {
     2152                        t->unit[t->curTextureUnit].gen.r = e;
     2153                        DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
     2154                        DIRTY(tb->dirty, g->neg_bitid);
     2155                    }
     2156                    else {
     2157                        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2158                            "glTexGen called with bad param: %lf", *param);
     2159                        return;
     2160                    }
     2161                    break;
     2162                case GL_OBJECT_PLANE:
     2163                    v.x = (GLfloat) param[0];
     2164                    v.y = (GLfloat) param[1];
     2165                    v.z = (GLfloat) param[2];
     2166                    v.w = (GLfloat) param[3];
     2167                    t->unit[t->curTextureUnit].objRCoeff = v;
     2168                    DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
     2169                    DIRTY(tb->dirty, g->neg_bitid);
     2170                    break;
     2171                case GL_EYE_PLANE:
     2172                    v.x = (GLfloat) param[0];
     2173                    v.y = (GLfloat) param[1];
     2174                    v.z = (GLfloat) param[2];
     2175                    v.w = (GLfloat) param[3];
     2176                    crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
     2177                    crStateTransformXformPointMatrixf(&inv, &v);
     2178                    t->unit[t->curTextureUnit].eyeRCoeff = v;
     2179                    DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
     2180                    DIRTY(tb->dirty, g->neg_bitid);
     2181                    break;
     2182                default:
     2183                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2184                                "glTexGen called with bogus pname: %d", pname);
     2185                    return;
     2186            }
     2187            break;
     2188        case GL_Q:
     2189            switch (pname) {
     2190                case GL_TEXTURE_GEN_MODE:
     2191                    e = (GLenum) *param;
     2192                    if (e == GL_OBJECT_LINEAR ||
     2193                        e == GL_EYE_LINEAR ||
     2194                        e == GL_SPHERE_MAP
    21952195#if defined(GL_ARB_texture_cube_map) || defined(GL_EXT_texture_cube_map) || defined(GL_NV_texgen_reflection)
    2196                                                 || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
    2197                                                         && g->extensions.ARB_texture_cube_map)
    2198 #endif
    2199                                         ) {
    2200                                                 t->unit[t->curTextureUnit].gen.q = e;
    2201                                                 DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
    2202                                                 DIRTY(tb->dirty, g->neg_bitid);
    2203                                         }
    2204                                         else {
    2205                                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2206                                                         "glTexGen called with bad param: %lf", *param);
    2207                                                 return;
    2208                                         }
    2209                                         break;
    2210                                 case GL_OBJECT_PLANE:
    2211                                         v.x = (GLfloat) param[0];
    2212                                         v.y = (GLfloat) param[1];
    2213                                         v.z = (GLfloat) param[2];
    2214                                         v.w = (GLfloat) param[3];
    2215                                         t->unit[t->curTextureUnit].objQCoeff = v;
    2216                                         DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
    2217                                         DIRTY(tb->dirty, g->neg_bitid);
    2218                                         break;
    2219                                 case GL_EYE_PLANE:
    2220                                         v.x = (GLfloat) param[0];
    2221                                         v.y = (GLfloat) param[1];
    2222                                         v.z = (GLfloat) param[2];
    2223                                         v.w = (GLfloat) param[3];
    2224                                         crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
    2225                                         crStateTransformXformPointMatrixf(&inv, &v);
    2226                                         t->unit[t->curTextureUnit].eyeQCoeff = v;
    2227                                         DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
    2228                                         DIRTY(tb->dirty, g->neg_bitid);
    2229                                         break;
    2230                                 default:
    2231                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2232                                                                 "glTexGen called with bogus pname: %d", pname);
    2233                                         return;
    2234                         }
    2235                         break;
    2236                 default:
    2237                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2238                                                 "glTexGen called with bogus coord: %d", coord);
    2239                         return;
    2240         }
     2196                        || ((e == GL_REFLECTION_MAP_ARB || e == GL_NORMAL_MAP_ARB)
     2197                            && g->extensions.ARB_texture_cube_map)
     2198#endif
     2199                    ) {
     2200                        t->unit[t->curTextureUnit].gen.q = e;
     2201                        DIRTY(tb->genMode[t->curTextureUnit], g->neg_bitid);
     2202                        DIRTY(tb->dirty, g->neg_bitid);
     2203                    }
     2204                    else {
     2205                        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2206                            "glTexGen called with bad param: %lf", *param);
     2207                        return;
     2208                    }
     2209                    break;
     2210                case GL_OBJECT_PLANE:
     2211                    v.x = (GLfloat) param[0];
     2212                    v.y = (GLfloat) param[1];
     2213                    v.z = (GLfloat) param[2];
     2214                    v.w = (GLfloat) param[3];
     2215                    t->unit[t->curTextureUnit].objQCoeff = v;
     2216                    DIRTY(tb->objGen[t->curTextureUnit], g->neg_bitid);
     2217                    DIRTY(tb->dirty, g->neg_bitid);
     2218                    break;
     2219                case GL_EYE_PLANE:
     2220                    v.x = (GLfloat) param[0];
     2221                    v.y = (GLfloat) param[1];
     2222                    v.z = (GLfloat) param[2];
     2223                    v.w = (GLfloat) param[3];
     2224                    crMatrixInvertTranspose(&inv, trans->modelViewStack.top);
     2225                    crStateTransformXformPointMatrixf(&inv, &v);
     2226                    t->unit[t->curTextureUnit].eyeQCoeff = v;
     2227                    DIRTY(tb->eyeGen[t->curTextureUnit], g->neg_bitid);
     2228                    DIRTY(tb->dirty, g->neg_bitid);
     2229                    break;
     2230                default:
     2231                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2232                                "glTexGen called with bogus pname: %d", pname);
     2233                    return;
     2234            }
     2235            break;
     2236        default:
     2237            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2238                        "glTexGen called with bogus coord: %d", coord);
     2239            return;
     2240    }
    22412241}
    22422242
     
    22452245crStateTexGenfv(GLenum coord, GLenum pname, const GLfloat *param)
    22462246{
    2247         GLdouble d_param;
    2248         GLvectord d_vector;
    2249         switch (pname)
    2250         {
    2251                 case GL_TEXTURE_GEN_MODE:
    2252                         d_param = (GLdouble) *param;
    2253                         crStateTexGendv( coord, pname, &d_param );
    2254                         break;
    2255                 case GL_OBJECT_PLANE:
    2256                 case GL_EYE_PLANE:
    2257                         d_vector.x = (GLdouble) param[0];
    2258                         d_vector.y = (GLdouble) param[1];
    2259                         d_vector.z = (GLdouble) param[2];
    2260                         d_vector.w = (GLdouble) param[3];
    2261                         crStateTexGendv( coord, pname, (const double *) &d_vector );
    2262                         break;
    2263                 default:
    2264                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2265                                                 "glTexGen called with bogus pname: %d", pname);
    2266                         return;
    2267         }
     2247    GLdouble d_param;
     2248    GLvectord d_vector;
     2249    switch (pname)
     2250    {
     2251        case GL_TEXTURE_GEN_MODE:
     2252            d_param = (GLdouble) *param;
     2253            crStateTexGendv( coord, pname, &d_param );
     2254            break;
     2255        case GL_OBJECT_PLANE:
     2256        case GL_EYE_PLANE:
     2257            d_vector.x = (GLdouble) param[0];
     2258            d_vector.y = (GLdouble) param[1];
     2259            d_vector.z = (GLdouble) param[2];
     2260            d_vector.w = (GLdouble) param[3];
     2261            crStateTexGendv( coord, pname, (const double *) &d_vector );
     2262            break;
     2263        default:
     2264            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2265                        "glTexGen called with bogus pname: %d", pname);
     2266            return;
     2267    }
    22682268}
    22692269
     
    22722272crStateTexGeniv(GLenum coord, GLenum pname, const GLint *param)
    22732273{
    2274         GLdouble d_param;
    2275         GLvectord d_vector;
    2276         switch (pname)
    2277         {
    2278                 case GL_TEXTURE_GEN_MODE:
    2279                         d_param = (GLdouble) *param;
    2280                         crStateTexGendv( coord, pname, &d_param );
    2281                         break;
    2282                 case GL_OBJECT_PLANE:
    2283                 case GL_EYE_PLANE:
    2284                         d_vector.x = (GLdouble) param[0];
    2285                         d_vector.y = (GLdouble) param[1];
    2286                         d_vector.z = (GLdouble) param[2];
    2287                         d_vector.w = (GLdouble) param[3];
    2288                         crStateTexGendv( coord, pname, (const double *) &d_vector );
    2289                         break;
    2290                 default:
    2291                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2292                                                 "glTexGen called with bogus pname: %d", pname);
    2293                         return;
    2294         }
     2274    GLdouble d_param;
     2275    GLvectord d_vector;
     2276    switch (pname)
     2277    {
     2278        case GL_TEXTURE_GEN_MODE:
     2279            d_param = (GLdouble) *param;
     2280            crStateTexGendv( coord, pname, &d_param );
     2281            break;
     2282        case GL_OBJECT_PLANE:
     2283        case GL_EYE_PLANE:
     2284            d_vector.x = (GLdouble) param[0];
     2285            d_vector.y = (GLdouble) param[1];
     2286            d_vector.z = (GLdouble) param[2];
     2287            d_vector.w = (GLdouble) param[3];
     2288            crStateTexGendv( coord, pname, (const double *) &d_vector );
     2289            break;
     2290        default:
     2291            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2292                        "glTexGen called with bogus pname: %d", pname);
     2293            return;
     2294    }
    22952295}
    22962296
     
    22992299crStateTexGend (GLenum coord, GLenum pname, GLdouble param)
    23002300{
    2301         crStateTexGendv( coord, pname, &param );
     2301    crStateTexGendv( coord, pname, &param );
    23022302}
    23032303
     
    23062306crStateTexGenf(GLenum coord, GLenum pname, GLfloat param)
    23072307{
    2308         GLdouble d_param = (GLdouble) param;
    2309         crStateTexGendv( coord, pname, &d_param );
     2308    GLdouble d_param = (GLdouble) param;
     2309    crStateTexGendv( coord, pname, &d_param );
    23102310}
    23112311
     
    23142314crStateTexGeni(GLenum coord, GLenum pname, GLint param)
    23152315{
    2316         GLdouble d_param = (GLdouble) param;
    2317         crStateTexGendv( coord, pname, &d_param );
     2316    GLdouble d_param = (GLdouble) param;
     2317    crStateTexGendv( coord, pname, &d_param );
    23182318}
    23192319
     
    23222322crStateGetTexGendv(GLenum coord, GLenum pname, GLdouble *param)
    23232323{
    2324         CRContext *g = GetCurrentContext();
    2325         CRTextureState *t = &(g->texture);
    2326 
    2327         if (g->current.inBeginEnd)
    2328         {
    2329                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2330                                         "glGetTexGen called in begin/end");
    2331                 return;
    2332         }
    2333 
    2334         switch (pname) {
    2335                 case GL_TEXTURE_GEN_MODE:
    2336                         switch (coord) {
    2337                                 case GL_S:
    2338                                         *param = (GLdouble) t->unit[t->curTextureUnit].gen.s;
    2339                                         break;
    2340                                 case GL_T:
    2341                                         *param = (GLdouble) t->unit[t->curTextureUnit].gen.t;
    2342                                         break;
    2343                                 case GL_R:
    2344                                         *param = (GLdouble) t->unit[t->curTextureUnit].gen.r;
    2345                                         break;
    2346                                 case GL_Q:
    2347                                         *param = (GLdouble) t->unit[t->curTextureUnit].gen.q;
    2348                                         break;
    2349                                 default:
    2350                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2351                                                                 "glGetTexGen called with bogus coord: %d", coord);
    2352                                         return;
    2353                         }
    2354                         break;
    2355                 case GL_OBJECT_PLANE:
    2356                         switch (coord) {
    2357                                 case GL_S:
    2358                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.x;
    2359                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.y;
    2360                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.z;
    2361                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.w;
    2362                                         break;
    2363                                 case GL_T:
    2364                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.x;
    2365                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.y;
    2366                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.z;
    2367                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.w;
    2368                                         break;
    2369                                 case GL_R:
    2370                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.x;
    2371                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.y;
    2372                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.z;
    2373                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.w;
    2374                                         break;
    2375                                 case GL_Q:
    2376                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.x;
    2377                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.y;
    2378                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.z;
    2379                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.w;
    2380                                         break;
    2381                                 default:
    2382                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2383                                                                 "glGetTexGen called with bogus coord: %d", coord);
    2384                                         return;
    2385                         }
    2386                         break;
    2387                 case GL_EYE_PLANE:
    2388                         switch (coord) {
    2389                                 case GL_S:
    2390                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.x;
    2391                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.y;
    2392                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.z;
    2393                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.w;
    2394                                         break;
    2395                                 case GL_T:
    2396                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.x;
    2397                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.y;
    2398                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.z;
    2399                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.w;
    2400                                         break;
    2401                                 case GL_R:
    2402                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.x;
    2403                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.y;
    2404                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.z;
    2405                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.w;
    2406                                         break;
    2407                                 case GL_Q:
    2408                                         param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.x;
    2409                                         param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.y;
    2410                                         param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.z;
    2411                                         param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.w;
    2412                                         break;
    2413                                 default:
    2414                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2415                                                                 "glGetTexGen called with bogus coord: %d", coord);
    2416                                         return;
    2417                         }
    2418                         break;
    2419                 default:
    2420                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2421                                                 "glGetTexGen called with bogus pname: %d", pname);
    2422                         return;
    2423         }
     2324    CRContext *g = GetCurrentContext();
     2325    CRTextureState *t = &(g->texture);
     2326
     2327    if (g->current.inBeginEnd)
     2328    {
     2329        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2330                    "glGetTexGen called in begin/end");
     2331        return;
     2332    }
     2333
     2334    switch (pname) {
     2335        case GL_TEXTURE_GEN_MODE:
     2336            switch (coord) {
     2337                case GL_S:
     2338                    *param = (GLdouble) t->unit[t->curTextureUnit].gen.s;
     2339                    break;
     2340                case GL_T:
     2341                    *param = (GLdouble) t->unit[t->curTextureUnit].gen.t;
     2342                    break;
     2343                case GL_R:
     2344                    *param = (GLdouble) t->unit[t->curTextureUnit].gen.r;
     2345                    break;
     2346                case GL_Q:
     2347                    *param = (GLdouble) t->unit[t->curTextureUnit].gen.q;
     2348                    break;
     2349                default:
     2350                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2351                                "glGetTexGen called with bogus coord: %d", coord);
     2352                    return;
     2353            }
     2354            break;
     2355        case GL_OBJECT_PLANE:
     2356            switch (coord) {
     2357                case GL_S:
     2358                    param[0] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.x;
     2359                    param[1] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.y;
     2360                    param[2] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.z;
     2361                    param[3] = (GLdouble) t->unit[t->curTextureUnit].objSCoeff.w;
     2362                    break;
     2363                case GL_T:
     2364                    param[0] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.x;
     2365                    param[1] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.y;
     2366                    param[2] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.z;
     2367                    param[3] = (GLdouble) t->unit[t->curTextureUnit].objTCoeff.w;
     2368                    break;
     2369                case GL_R:
     2370                    param[0] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.x;
     2371                    param[1] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.y;
     2372                    param[2] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.z;
     2373                    param[3] = (GLdouble) t->unit[t->curTextureUnit].objRCoeff.w;
     2374                    break;
     2375                case GL_Q:
     2376                    param[0] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.x;
     2377                    param[1] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.y;
     2378                    param[2] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.z;
     2379                    param[3] = (GLdouble) t->unit[t->curTextureUnit].objQCoeff.w;
     2380                    break;
     2381                default:
     2382                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2383                                "glGetTexGen called with bogus coord: %d", coord);
     2384                    return;
     2385            }
     2386            break;
     2387        case GL_EYE_PLANE:
     2388            switch (coord) {
     2389                case GL_S:
     2390                    param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.x;
     2391                    param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.y;
     2392                    param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.z;
     2393                    param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeSCoeff.w;
     2394                    break;
     2395                case GL_T:
     2396                    param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.x;
     2397                    param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.y;
     2398                    param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.z;
     2399                    param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeTCoeff.w;
     2400                    break;
     2401                case GL_R:
     2402                    param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.x;
     2403                    param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.y;
     2404                    param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.z;
     2405                    param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeRCoeff.w;
     2406                    break;
     2407                case GL_Q:
     2408                    param[0] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.x;
     2409                    param[1] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.y;
     2410                    param[2] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.z;
     2411                    param[3] = (GLdouble) t->unit[t->curTextureUnit].eyeQCoeff.w;
     2412                    break;
     2413                default:
     2414                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2415                                "glGetTexGen called with bogus coord: %d", coord);
     2416                    return;
     2417            }
     2418            break;
     2419        default:
     2420            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2421                        "glGetTexGen called with bogus pname: %d", pname);
     2422            return;
     2423    }
    24242424}
    24252425
     
    24282428crStateGetTexGenfv(GLenum coord, GLenum pname, GLfloat *param)
    24292429{
    2430         CRContext *g = GetCurrentContext();
    2431         CRTextureState *t = &(g->texture);
    2432 
    2433         if (g->current.inBeginEnd)
    2434         {
    2435                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2436                                         "glGetTexGenfv called in begin/end");
    2437                 return;
    2438         }
    2439 
    2440         switch (pname) {
    2441                 case GL_TEXTURE_GEN_MODE:
    2442                         switch (coord) {
    2443                                 case GL_S:
    2444                                         *param = (GLfloat) t->unit[t->curTextureUnit].gen.s;
    2445                                         break;
    2446                                 case GL_T:
    2447                                         *param = (GLfloat) t->unit[t->curTextureUnit].gen.t;
    2448                                         break;
    2449                                 case GL_R:
    2450                                         *param = (GLfloat) t->unit[t->curTextureUnit].gen.r;
    2451                                         break;
    2452                                 case GL_Q:
    2453                                         *param = (GLfloat) t->unit[t->curTextureUnit].gen.q;
    2454                                         break;
    2455                                 default:
    2456                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2457                                                                 "glGetTexGenfv called with bogus coord: %d", coord);
    2458                                         return;
    2459                         }
    2460                         break;
    2461                 case GL_OBJECT_PLANE:
    2462                         switch (coord) {
    2463                                 case GL_S:
    2464                                         param[0] = t->unit[t->curTextureUnit].objSCoeff.x;
    2465                                         param[1] = t->unit[t->curTextureUnit].objSCoeff.y;
    2466                                         param[2] = t->unit[t->curTextureUnit].objSCoeff.z;
    2467                                         param[3] = t->unit[t->curTextureUnit].objSCoeff.w;
    2468                                         break;
    2469                                 case GL_T:
    2470                                         param[0] =  t->unit[t->curTextureUnit].objTCoeff.x;
    2471                                         param[1] =  t->unit[t->curTextureUnit].objTCoeff.y;
    2472                                         param[2] =  t->unit[t->curTextureUnit].objTCoeff.z;
    2473                                         param[3] =  t->unit[t->curTextureUnit].objTCoeff.w;
    2474                                         break;
    2475                                 case GL_R:
    2476                                         param[0] =  t->unit[t->curTextureUnit].objRCoeff.x;
    2477                                         param[1] =  t->unit[t->curTextureUnit].objRCoeff.y;
    2478                                         param[2] =  t->unit[t->curTextureUnit].objRCoeff.z;
    2479                                         param[3] =  t->unit[t->curTextureUnit].objRCoeff.w;
    2480                                         break;
    2481                                 case GL_Q:
    2482                                         param[0] =  t->unit[t->curTextureUnit].objQCoeff.x;
    2483                                         param[1] =  t->unit[t->curTextureUnit].objQCoeff.y;
    2484                                         param[2] =  t->unit[t->curTextureUnit].objQCoeff.z;
    2485                                         param[3] =  t->unit[t->curTextureUnit].objQCoeff.w;
    2486                                         break;
    2487                                 default:
    2488                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2489                                                                 "glGetTexGenfv called with bogus coord: %d", coord);
    2490                                         return;
    2491                         }
    2492                         break;
    2493                 case GL_EYE_PLANE:
    2494                         switch (coord) {
    2495                                 case GL_S:
    2496                                         param[0] =  t->unit[t->curTextureUnit].eyeSCoeff.x;
    2497                                         param[1] =  t->unit[t->curTextureUnit].eyeSCoeff.y;
    2498                                         param[2] =  t->unit[t->curTextureUnit].eyeSCoeff.z;
    2499                                         param[3] =  t->unit[t->curTextureUnit].eyeSCoeff.w;
    2500                                         break;
    2501                                 case GL_T:
    2502                                         param[0] =  t->unit[t->curTextureUnit].eyeTCoeff.x;
    2503                                         param[1] =  t->unit[t->curTextureUnit].eyeTCoeff.y;
    2504                                         param[2] =  t->unit[t->curTextureUnit].eyeTCoeff.z;
    2505                                         param[3] =  t->unit[t->curTextureUnit].eyeTCoeff.w;
    2506                                         break;
    2507                                 case GL_R:
    2508                                         param[0] =  t->unit[t->curTextureUnit].eyeRCoeff.x;
    2509                                         param[1] =  t->unit[t->curTextureUnit].eyeRCoeff.y;
    2510                                         param[2] =  t->unit[t->curTextureUnit].eyeRCoeff.z;
    2511                                         param[3] =  t->unit[t->curTextureUnit].eyeRCoeff.w;
    2512                                         break;
    2513                                 case GL_Q:
    2514                                         param[0] =  t->unit[t->curTextureUnit].eyeQCoeff.x;
    2515                                         param[1] =  t->unit[t->curTextureUnit].eyeQCoeff.y;
    2516                                         param[2] =  t->unit[t->curTextureUnit].eyeQCoeff.z;
    2517                                         param[3] =  t->unit[t->curTextureUnit].eyeQCoeff.w;
    2518                                         break;
    2519                                 default:
    2520                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2521                                                                 "glGetTexGenfv called with bogus coord: %d", coord);
    2522                                         return;
    2523                         }
    2524                         break;
    2525                 default:
    2526                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2527                                                 "glGetTexGenfv called with bogus pname: %d", pname);
    2528                         return;
    2529         }
     2430    CRContext *g = GetCurrentContext();
     2431    CRTextureState *t = &(g->texture);
     2432
     2433    if (g->current.inBeginEnd)
     2434    {
     2435        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2436                    "glGetTexGenfv called in begin/end");
     2437        return;
     2438    }
     2439
     2440    switch (pname) {
     2441        case GL_TEXTURE_GEN_MODE:
     2442            switch (coord) {
     2443                case GL_S:
     2444                    *param = (GLfloat) t->unit[t->curTextureUnit].gen.s;
     2445                    break;
     2446                case GL_T:
     2447                    *param = (GLfloat) t->unit[t->curTextureUnit].gen.t;
     2448                    break;
     2449                case GL_R:
     2450                    *param = (GLfloat) t->unit[t->curTextureUnit].gen.r;
     2451                    break;
     2452                case GL_Q:
     2453                    *param = (GLfloat) t->unit[t->curTextureUnit].gen.q;
     2454                    break;
     2455                default:
     2456                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2457                                "glGetTexGenfv called with bogus coord: %d", coord);
     2458                    return;
     2459            }
     2460            break;
     2461        case GL_OBJECT_PLANE:
     2462            switch (coord) {
     2463                case GL_S:
     2464                    param[0] = t->unit[t->curTextureUnit].objSCoeff.x;
     2465                    param[1] = t->unit[t->curTextureUnit].objSCoeff.y;
     2466                    param[2] = t->unit[t->curTextureUnit].objSCoeff.z;
     2467                    param[3] = t->unit[t->curTextureUnit].objSCoeff.w;
     2468                    break;
     2469                case GL_T:
     2470                    param[0] =  t->unit[t->curTextureUnit].objTCoeff.x;
     2471                    param[1] =  t->unit[t->curTextureUnit].objTCoeff.y;
     2472                    param[2] =  t->unit[t->curTextureUnit].objTCoeff.z;
     2473                    param[3] =  t->unit[t->curTextureUnit].objTCoeff.w;
     2474                    break;
     2475                case GL_R:
     2476                    param[0] =  t->unit[t->curTextureUnit].objRCoeff.x;
     2477                    param[1] =  t->unit[t->curTextureUnit].objRCoeff.y;
     2478                    param[2] =  t->unit[t->curTextureUnit].objRCoeff.z;
     2479                    param[3] =  t->unit[t->curTextureUnit].objRCoeff.w;
     2480                    break;
     2481                case GL_Q:
     2482                    param[0] =  t->unit[t->curTextureUnit].objQCoeff.x;
     2483                    param[1] =  t->unit[t->curTextureUnit].objQCoeff.y;
     2484                    param[2] =  t->unit[t->curTextureUnit].objQCoeff.z;
     2485                    param[3] =  t->unit[t->curTextureUnit].objQCoeff.w;
     2486                    break;
     2487                default:
     2488                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2489                                "glGetTexGenfv called with bogus coord: %d", coord);
     2490                    return;
     2491            }
     2492            break;
     2493        case GL_EYE_PLANE:
     2494            switch (coord) {
     2495                case GL_S:
     2496                    param[0] =  t->unit[t->curTextureUnit].eyeSCoeff.x;
     2497                    param[1] =  t->unit[t->curTextureUnit].eyeSCoeff.y;
     2498                    param[2] =  t->unit[t->curTextureUnit].eyeSCoeff.z;
     2499                    param[3] =  t->unit[t->curTextureUnit].eyeSCoeff.w;
     2500                    break;
     2501                case GL_T:
     2502                    param[0] =  t->unit[t->curTextureUnit].eyeTCoeff.x;
     2503                    param[1] =  t->unit[t->curTextureUnit].eyeTCoeff.y;
     2504                    param[2] =  t->unit[t->curTextureUnit].eyeTCoeff.z;
     2505                    param[3] =  t->unit[t->curTextureUnit].eyeTCoeff.w;
     2506                    break;
     2507                case GL_R:
     2508                    param[0] =  t->unit[t->curTextureUnit].eyeRCoeff.x;
     2509                    param[1] =  t->unit[t->curTextureUnit].eyeRCoeff.y;
     2510                    param[2] =  t->unit[t->curTextureUnit].eyeRCoeff.z;
     2511                    param[3] =  t->unit[t->curTextureUnit].eyeRCoeff.w;
     2512                    break;
     2513                case GL_Q:
     2514                    param[0] =  t->unit[t->curTextureUnit].eyeQCoeff.x;
     2515                    param[1] =  t->unit[t->curTextureUnit].eyeQCoeff.y;
     2516                    param[2] =  t->unit[t->curTextureUnit].eyeQCoeff.z;
     2517                    param[3] =  t->unit[t->curTextureUnit].eyeQCoeff.w;
     2518                    break;
     2519                default:
     2520                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2521                                "glGetTexGenfv called with bogus coord: %d", coord);
     2522                    return;
     2523            }
     2524            break;
     2525        default:
     2526            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2527                        "glGetTexGenfv called with bogus pname: %d", pname);
     2528            return;
     2529    }
    25302530}
    25312531
     
    25342534crStateGetTexGeniv(GLenum coord, GLenum pname, GLint *param)
    25352535{
    2536         CRContext *g = GetCurrentContext();
    2537         CRTextureState *t = &(g->texture);
    2538 
    2539         if (g->current.inBeginEnd)
    2540         {
    2541                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2542                                         "glGetTexGeniv called in begin/end");
    2543                 return;
    2544         }
    2545 
    2546         switch (pname) {
    2547                 case GL_TEXTURE_GEN_MODE:
    2548                         switch (coord) {
    2549                                 case GL_S:
    2550                                         *param = (GLint) t->unit[t->curTextureUnit].gen.s;
    2551                                         break;
    2552                                 case GL_T:
    2553                                         *param = (GLint) t->unit[t->curTextureUnit].gen.t;
    2554                                         break;
    2555                                 case GL_R:
    2556                                         *param = (GLint) t->unit[t->curTextureUnit].gen.r;
    2557                                         break;
    2558                                 case GL_Q:
    2559                                         *param = (GLint) t->unit[t->curTextureUnit].gen.q;
    2560                                         break;
    2561                                 default:
    2562                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2563                                                                 "glGetTexGeniv called with bogus coord: %d", coord);
    2564                                         return;
    2565                         }
    2566                         break;
    2567                 case GL_OBJECT_PLANE:
    2568                         switch (coord) {
    2569                                 case GL_S:
    2570                                         param[0] = (GLint) t->unit[t->curTextureUnit].objSCoeff.x;
    2571                                         param[1] = (GLint) t->unit[t->curTextureUnit].objSCoeff.y;
    2572                                         param[2] = (GLint) t->unit[t->curTextureUnit].objSCoeff.z;
    2573                                         param[3] = (GLint) t->unit[t->curTextureUnit].objSCoeff.w;
    2574                                         break;
    2575                                 case GL_T:
    2576                                         param[0] = (GLint) t->unit[t->curTextureUnit].objTCoeff.x;
    2577                                         param[1] = (GLint) t->unit[t->curTextureUnit].objTCoeff.y;
    2578                                         param[2] = (GLint) t->unit[t->curTextureUnit].objTCoeff.z;
    2579                                         param[3] = (GLint) t->unit[t->curTextureUnit].objTCoeff.w;
    2580                                         break;
    2581                                 case GL_R:
    2582                                         param[0] = (GLint) t->unit[t->curTextureUnit].objRCoeff.x;
    2583                                         param[1] = (GLint) t->unit[t->curTextureUnit].objRCoeff.y;
    2584                                         param[2] = (GLint) t->unit[t->curTextureUnit].objRCoeff.z;
    2585                                         param[3] = (GLint) t->unit[t->curTextureUnit].objRCoeff.w;
    2586                                         break;
    2587                                 case GL_Q:
    2588                                         param[0] = (GLint) t->unit[t->curTextureUnit].objQCoeff.x;
    2589                                         param[1] = (GLint) t->unit[t->curTextureUnit].objQCoeff.y;
    2590                                         param[2] = (GLint) t->unit[t->curTextureUnit].objQCoeff.z;
    2591                                         param[3] = (GLint) t->unit[t->curTextureUnit].objQCoeff.w;
    2592                                         break;
    2593                                 default:
    2594                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2595                                                                 "glGetTexGeniv called with bogus coord: %d", coord);
    2596                                         return;
    2597                         }
    2598                         break;
    2599                 case GL_EYE_PLANE:
    2600                         switch (coord) {
    2601                                 case GL_S:
    2602                                         param[0] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.x;
    2603                                         param[1] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.y;
    2604                                         param[2] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.z;
    2605                                         param[3] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.w;
    2606                                         break;
    2607                                 case GL_T:
    2608                                         param[0] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.x;
    2609                                         param[1] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.y;
    2610                                         param[2] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.z;
    2611                                         param[3] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.w;
    2612                                         break;
    2613                                 case GL_R:
    2614                                         param[0] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.x;
    2615                                         param[1] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.y;
    2616                                         param[2] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.z;
    2617                                         param[3] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.w;
    2618                                         break;
    2619                                 case GL_Q:
    2620                                         param[0] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.x;
    2621                                         param[1] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.y;
    2622                                         param[2] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.z;
    2623                                         param[3] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.w;
    2624                                         break;
    2625                                 default:
    2626                                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2627                                                                 "glGetTexGeniv called with bogus coord: %d", coord);
    2628                                         return;
    2629                         }
    2630                         break;
    2631                 default:
    2632                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2633                                                 "glGetTexGen called with bogus pname: %d", pname);
    2634                         return;
    2635         }
     2536    CRContext *g = GetCurrentContext();
     2537    CRTextureState *t = &(g->texture);
     2538
     2539    if (g->current.inBeginEnd)
     2540    {
     2541        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2542                    "glGetTexGeniv called in begin/end");
     2543        return;
     2544    }
     2545
     2546    switch (pname) {
     2547        case GL_TEXTURE_GEN_MODE:
     2548            switch (coord) {
     2549                case GL_S:
     2550                    *param = (GLint) t->unit[t->curTextureUnit].gen.s;
     2551                    break;
     2552                case GL_T:
     2553                    *param = (GLint) t->unit[t->curTextureUnit].gen.t;
     2554                    break;
     2555                case GL_R:
     2556                    *param = (GLint) t->unit[t->curTextureUnit].gen.r;
     2557                    break;
     2558                case GL_Q:
     2559                    *param = (GLint) t->unit[t->curTextureUnit].gen.q;
     2560                    break;
     2561                default:
     2562                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2563                                "glGetTexGeniv called with bogus coord: %d", coord);
     2564                    return;
     2565            }
     2566            break;
     2567        case GL_OBJECT_PLANE:
     2568            switch (coord) {
     2569                case GL_S:
     2570                    param[0] = (GLint) t->unit[t->curTextureUnit].objSCoeff.x;
     2571                    param[1] = (GLint) t->unit[t->curTextureUnit].objSCoeff.y;
     2572                    param[2] = (GLint) t->unit[t->curTextureUnit].objSCoeff.z;
     2573                    param[3] = (GLint) t->unit[t->curTextureUnit].objSCoeff.w;
     2574                    break;
     2575                case GL_T:
     2576                    param[0] = (GLint) t->unit[t->curTextureUnit].objTCoeff.x;
     2577                    param[1] = (GLint) t->unit[t->curTextureUnit].objTCoeff.y;
     2578                    param[2] = (GLint) t->unit[t->curTextureUnit].objTCoeff.z;
     2579                    param[3] = (GLint) t->unit[t->curTextureUnit].objTCoeff.w;
     2580                    break;
     2581                case GL_R:
     2582                    param[0] = (GLint) t->unit[t->curTextureUnit].objRCoeff.x;
     2583                    param[1] = (GLint) t->unit[t->curTextureUnit].objRCoeff.y;
     2584                    param[2] = (GLint) t->unit[t->curTextureUnit].objRCoeff.z;
     2585                    param[3] = (GLint) t->unit[t->curTextureUnit].objRCoeff.w;
     2586                    break;
     2587                case GL_Q:
     2588                    param[0] = (GLint) t->unit[t->curTextureUnit].objQCoeff.x;
     2589                    param[1] = (GLint) t->unit[t->curTextureUnit].objQCoeff.y;
     2590                    param[2] = (GLint) t->unit[t->curTextureUnit].objQCoeff.z;
     2591                    param[3] = (GLint) t->unit[t->curTextureUnit].objQCoeff.w;
     2592                    break;
     2593                default:
     2594                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2595                                "glGetTexGeniv called with bogus coord: %d", coord);
     2596                    return;
     2597            }
     2598            break;
     2599        case GL_EYE_PLANE:
     2600            switch (coord) {
     2601                case GL_S:
     2602                    param[0] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.x;
     2603                    param[1] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.y;
     2604                    param[2] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.z;
     2605                    param[3] = (GLint) t->unit[t->curTextureUnit].eyeSCoeff.w;
     2606                    break;
     2607                case GL_T:
     2608                    param[0] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.x;
     2609                    param[1] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.y;
     2610                    param[2] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.z;
     2611                    param[3] = (GLint) t->unit[t->curTextureUnit].eyeTCoeff.w;
     2612                    break;
     2613                case GL_R:
     2614                    param[0] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.x;
     2615                    param[1] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.y;
     2616                    param[2] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.z;
     2617                    param[3] = (GLint) t->unit[t->curTextureUnit].eyeRCoeff.w;
     2618                    break;
     2619                case GL_Q:
     2620                    param[0] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.x;
     2621                    param[1] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.y;
     2622                    param[2] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.z;
     2623                    param[3] = (GLint) t->unit[t->curTextureUnit].eyeQCoeff.w;
     2624                    break;
     2625                default:
     2626                    crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2627                                "glGetTexGeniv called with bogus coord: %d", coord);
     2628                    return;
     2629            }
     2630            break;
     2631        default:
     2632            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2633                        "glGetTexGen called with bogus pname: %d", pname);
     2634            return;
     2635    }
    26362636}
    26372637
     
    26392639void STATE_APIENTRY
    26402640crStateGetTexLevelParameterfv(GLenum target, GLint level,
    2641                                                                                                                         GLenum pname, GLfloat *params)
    2642 {
    2643         CRContext *g = GetCurrentContext();
    2644         CRTextureState *t = &(g->texture);
    2645         CRTextureObj *tobj;
    2646         CRTextureLevel *timg;
    2647 
    2648         if (g->current.inBeginEnd)
    2649         {
    2650                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2651                         "glGetTexLevelParameterfv called in begin/end");
    2652                 return;
    2653         }
    2654 
    2655         if (level < 0 && level > t->maxLevel)
    2656         {
    2657                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    2658                         "glGetTexLevelParameterfv: Invalid level: %d", level);
    2659                 return;
    2660         }
    2661 
    2662         crStateGetTextureObjectAndImage(g, target, level, &tobj, &timg);
    2663         if (!timg)
    2664         {
    2665                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2666                         "GetTexLevelParameterfv: invalid target: 0x%x or level %d",
    2667                         target, level);
    2668                 return;
    2669         }
    2670 
    2671         switch (pname)
    2672         {
    2673                 case GL_TEXTURE_WIDTH:
    2674                         *params = (GLfloat) timg->width;
    2675                         break;
    2676                 case GL_TEXTURE_HEIGHT:
    2677                         *params = (GLfloat) timg->height;
    2678                         break;
     2641                                                            GLenum pname, GLfloat *params)
     2642{
     2643    CRContext *g = GetCurrentContext();
     2644    CRTextureState *t = &(g->texture);
     2645    CRTextureObj *tobj;
     2646    CRTextureLevel *timg;
     2647
     2648    if (g->current.inBeginEnd)
     2649    {
     2650        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2651            "glGetTexLevelParameterfv called in begin/end");
     2652        return;
     2653    }
     2654
     2655    if (level < 0 && level > t->maxLevel)
     2656    {
     2657        crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     2658            "glGetTexLevelParameterfv: Invalid level: %d", level);
     2659        return;
     2660    }
     2661
     2662    crStateGetTextureObjectAndImage(g, target, level, &tobj, &timg);
     2663    if (!timg)
     2664    {
     2665        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2666            "GetTexLevelParameterfv: invalid target: 0x%x or level %d",
     2667            target, level);
     2668        return;
     2669    }
     2670
     2671    switch (pname)
     2672    {
     2673        case GL_TEXTURE_WIDTH:
     2674            *params = (GLfloat) timg->width;
     2675            break;
     2676        case GL_TEXTURE_HEIGHT:
     2677            *params = (GLfloat) timg->height;
     2678            break;
    26792679#ifdef CR_OPENGL_VERSION_1_2
    2680                 case GL_TEXTURE_DEPTH:
    2681                         *params = (GLfloat) timg->depth;
    2682                         break;
    2683 #endif
    2684                 case GL_TEXTURE_INTERNAL_FORMAT:
    2685                         *params = (GLfloat) timg->internalFormat;
    2686                         break;
    2687                 case GL_TEXTURE_BORDER:
    2688                         *params = (GLfloat) timg->border;
    2689                         break;
    2690                 case GL_TEXTURE_RED_SIZE:
    2691                         *params = (GLfloat) timg->texFormat->redbits;
    2692                         break;
    2693                 case GL_TEXTURE_GREEN_SIZE:
    2694                         *params = (GLfloat) timg->texFormat->greenbits;
    2695                         break;
    2696                 case GL_TEXTURE_BLUE_SIZE:
    2697                         *params = (GLfloat) timg->texFormat->bluebits;
    2698                         break;
    2699                 case GL_TEXTURE_ALPHA_SIZE:
    2700                         *params = (GLfloat) timg->texFormat->alphabits;
    2701                         break;
    2702                 case GL_TEXTURE_INTENSITY_SIZE:
    2703                         *params = (GLfloat) timg->texFormat->intensitybits;
    2704                         break;
    2705                 case GL_TEXTURE_LUMINANCE_SIZE:
    2706                         *params = (GLfloat) timg->texFormat->luminancebits;
    2707                         break;
     2680        case GL_TEXTURE_DEPTH:
     2681            *params = (GLfloat) timg->depth;
     2682            break;
     2683#endif
     2684        case GL_TEXTURE_INTERNAL_FORMAT:
     2685            *params = (GLfloat) timg->internalFormat;
     2686            break;
     2687        case GL_TEXTURE_BORDER:
     2688            *params = (GLfloat) timg->border;
     2689            break;
     2690        case GL_TEXTURE_RED_SIZE:
     2691            *params = (GLfloat) timg->texFormat->redbits;
     2692            break;
     2693        case GL_TEXTURE_GREEN_SIZE:
     2694            *params = (GLfloat) timg->texFormat->greenbits;
     2695            break;
     2696        case GL_TEXTURE_BLUE_SIZE:
     2697            *params = (GLfloat) timg->texFormat->bluebits;
     2698            break;
     2699        case GL_TEXTURE_ALPHA_SIZE:
     2700            *params = (GLfloat) timg->texFormat->alphabits;
     2701            break;
     2702        case GL_TEXTURE_INTENSITY_SIZE:
     2703            *params = (GLfloat) timg->texFormat->intensitybits;
     2704            break;
     2705        case GL_TEXTURE_LUMINANCE_SIZE:
     2706            *params = (GLfloat) timg->texFormat->luminancebits;
     2707            break;
    27082708#if CR_ARB_texture_compression
    2709                 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
    2710                         *params = (GLfloat) timg->bytes;
    2711                         break;
    2712                 case GL_TEXTURE_COMPRESSED_ARB:
    2713                         *params = (GLfloat) timg->compressed;
    2714                         break;
    2715 #endif
    2716                 default:
    2717                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2718                                 "GetTexLevelParameterfv: invalid pname: 0x%x",
    2719                                 pname);
    2720                         return;
    2721         }
     2709        case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
     2710            *params = (GLfloat) timg->bytes;
     2711            break;
     2712        case GL_TEXTURE_COMPRESSED_ARB:
     2713            *params = (GLfloat) timg->compressed;
     2714            break;
     2715#endif
     2716        default:
     2717            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2718                "GetTexLevelParameterfv: invalid pname: 0x%x",
     2719                pname);
     2720            return;
     2721    }
    27222722}
    27232723
     
    27252725void STATE_APIENTRY
    27262726crStateGetTexLevelParameteriv(GLenum target, GLint level,
    2727                                                                                                                         GLenum pname, GLint *params)
    2728 {
    2729         CRContext *g = GetCurrentContext();
    2730         CRTextureState *t = &(g->texture);
    2731         CRTextureObj *tobj;
    2732         CRTextureLevel *timg;
    2733 
    2734         if (g->current.inBeginEnd)
    2735         {
    2736                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2737                         "glGetTexLevelParameteriv called in begin/end");
    2738                 return;
    2739         }
    2740 
    2741         if (level < 0 && level > t->maxLevel)
    2742         {
    2743                 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
    2744                         "glGetTexLevelParameteriv: Invalid level: %d", level);
    2745                 return;
    2746         }
    2747 
    2748         crStateGetTextureObjectAndImage(g, target, level, &tobj, &timg);
    2749         if (!timg)
    2750         {
    2751                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2752                         "GetTexLevelParameteriv: invalid target: 0x%x",
    2753                         target);
    2754                 return;
    2755         }
    2756 
    2757         switch (pname)
    2758         {
    2759                 case GL_TEXTURE_WIDTH:
    2760                         *params = (GLint) timg->width;
    2761                         break;
    2762                 case GL_TEXTURE_HEIGHT:
    2763                         *params = (GLint) timg->height;
    2764                         break;
     2727                                                            GLenum pname, GLint *params)
     2728{
     2729    CRContext *g = GetCurrentContext();
     2730    CRTextureState *t = &(g->texture);
     2731    CRTextureObj *tobj;
     2732    CRTextureLevel *timg;
     2733
     2734    if (g->current.inBeginEnd)
     2735    {
     2736        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2737            "glGetTexLevelParameteriv called in begin/end");
     2738        return;
     2739    }
     2740
     2741    if (level < 0 && level > t->maxLevel)
     2742    {
     2743        crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
     2744            "glGetTexLevelParameteriv: Invalid level: %d", level);
     2745        return;
     2746    }
     2747
     2748    crStateGetTextureObjectAndImage(g, target, level, &tobj, &timg);
     2749    if (!timg)
     2750    {
     2751        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2752            "GetTexLevelParameteriv: invalid target: 0x%x",
     2753            target);
     2754        return;
     2755    }
     2756
     2757    switch (pname)
     2758    {
     2759        case GL_TEXTURE_WIDTH:
     2760            *params = (GLint) timg->width;
     2761            break;
     2762        case GL_TEXTURE_HEIGHT:
     2763            *params = (GLint) timg->height;
     2764            break;
    27652765#ifdef CR_OPENGL_VERSION_1_2
    2766                 case GL_TEXTURE_DEPTH:
    2767                         *params = (GLint) timg->depth;
    2768                         break;
    2769 #endif
    2770                 case GL_TEXTURE_INTERNAL_FORMAT:
    2771                         *params = (GLint) timg->internalFormat;
    2772                         break;
    2773                 case GL_TEXTURE_BORDER:
    2774                         *params = (GLint) timg->border;
    2775                         break;
    2776                 case GL_TEXTURE_RED_SIZE:
    2777                         *params = (GLint) timg->texFormat->redbits;
    2778                         break;
    2779                 case GL_TEXTURE_GREEN_SIZE:
    2780                         *params = (GLint) timg->texFormat->greenbits;
    2781                         break;
    2782                 case GL_TEXTURE_BLUE_SIZE:
    2783                         *params = (GLint) timg->texFormat->bluebits;
    2784                         break;
    2785                 case GL_TEXTURE_ALPHA_SIZE:
    2786                         *params = (GLint) timg->texFormat->alphabits;
    2787                         break;
    2788                 case GL_TEXTURE_INTENSITY_SIZE:
    2789                         *params = (GLint) timg->texFormat->intensitybits;
    2790                         break;
    2791                 case GL_TEXTURE_LUMINANCE_SIZE:
    2792                         *params = (GLint) timg->texFormat->luminancebits;
    2793                         break;
     2766        case GL_TEXTURE_DEPTH:
     2767            *params = (GLint) timg->depth;
     2768            break;
     2769#endif
     2770        case GL_TEXTURE_INTERNAL_FORMAT:
     2771            *params = (GLint) timg->internalFormat;
     2772            break;
     2773        case GL_TEXTURE_BORDER:
     2774            *params = (GLint) timg->border;
     2775            break;
     2776        case GL_TEXTURE_RED_SIZE:
     2777            *params = (GLint) timg->texFormat->redbits;
     2778            break;
     2779        case GL_TEXTURE_GREEN_SIZE:
     2780            *params = (GLint) timg->texFormat->greenbits;
     2781            break;
     2782        case GL_TEXTURE_BLUE_SIZE:
     2783            *params = (GLint) timg->texFormat->bluebits;
     2784            break;
     2785        case GL_TEXTURE_ALPHA_SIZE:
     2786            *params = (GLint) timg->texFormat->alphabits;
     2787            break;
     2788        case GL_TEXTURE_INTENSITY_SIZE:
     2789            *params = (GLint) timg->texFormat->intensitybits;
     2790            break;
     2791        case GL_TEXTURE_LUMINANCE_SIZE:
     2792            *params = (GLint) timg->texFormat->luminancebits;
     2793            break;
    27942794
    27952795#if 0
    2796                 /* XXX TODO */
    2797                 case GL_TEXTURE_DEPTH_SIZE:
    2798                         *params = (GLint) timg->texFormat->depthSize;
    2799                         break;
     2796        /* XXX TODO */
     2797        case GL_TEXTURE_DEPTH_SIZE:
     2798            *params = (GLint) timg->texFormat->depthSize;
     2799            break;
    28002800#endif
    28012801#if CR_ARB_texture_compression
    2802                 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
    2803                         *params = (GLint) timg->bytes;
    2804                         break;
    2805                 case GL_TEXTURE_COMPRESSED_ARB:
    2806                         *params = (GLint) timg->compressed;
    2807                         break;
    2808 #endif
    2809                 default:
    2810                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2811                                 "GetTexLevelParameteriv: invalid pname: 0x%x",
    2812                                 pname);
    2813                         return;
    2814         }
     2802        case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
     2803            *params = (GLint) timg->bytes;
     2804            break;
     2805        case GL_TEXTURE_COMPRESSED_ARB:
     2806            *params = (GLint) timg->compressed;
     2807            break;
     2808#endif
     2809        default:
     2810            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2811                "GetTexLevelParameteriv: invalid pname: 0x%x",
     2812                pname);
     2813            return;
     2814    }
    28152815}
    28162816
     
    28192819crStateGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
    28202820{
    2821         CRContext *g = GetCurrentContext();
    2822         CRTextureObj *tobj;
    2823         CRTextureLevel *tl;
    2824 
    2825         if (g->current.inBeginEnd)
    2826         {
    2827                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2828                                         "glGetTexParameterfv called in begin/end");
    2829                 return;
    2830         }
    2831 
    2832         crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
    2833         if (!tobj)
    2834         {
    2835                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2836                         "glGetTexParameterfv: invalid target: 0x%x", target);
    2837                 return;
    2838         }
    2839 
    2840         switch (pname)
    2841         {
    2842                 case GL_TEXTURE_MAG_FILTER:
    2843                         *params = (GLfloat) tobj->magFilter;
    2844                         break;
    2845                 case GL_TEXTURE_MIN_FILTER:
    2846                         *params = (GLfloat) tobj->minFilter;
    2847                         break;
    2848                 case GL_TEXTURE_WRAP_S:
    2849                         *params = (GLfloat) tobj->wrapS;
    2850                         break;
    2851                 case GL_TEXTURE_WRAP_T:
    2852                         *params = (GLfloat) tobj->wrapT;
    2853                         break;
     2821    CRContext *g = GetCurrentContext();
     2822    CRTextureObj *tobj;
     2823    CRTextureLevel *tl;
     2824
     2825    if (g->current.inBeginEnd)
     2826    {
     2827        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2828                    "glGetTexParameterfv called in begin/end");
     2829        return;
     2830    }
     2831
     2832    crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
     2833    if (!tobj)
     2834    {
     2835        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2836            "glGetTexParameterfv: invalid target: 0x%x", target);
     2837        return;
     2838    }
     2839
     2840    switch (pname)
     2841    {
     2842        case GL_TEXTURE_MAG_FILTER:
     2843            *params = (GLfloat) tobj->magFilter;
     2844            break;
     2845        case GL_TEXTURE_MIN_FILTER:
     2846            *params = (GLfloat) tobj->minFilter;
     2847            break;
     2848        case GL_TEXTURE_WRAP_S:
     2849            *params = (GLfloat) tobj->wrapS;
     2850            break;
     2851        case GL_TEXTURE_WRAP_T:
     2852            *params = (GLfloat) tobj->wrapT;
     2853            break;
    28542854#ifdef CR_OPENGL_VERSION_1_2
    2855                 case GL_TEXTURE_WRAP_R:
    2856                         *params = (GLfloat) tobj->wrapR;
    2857                         break;
    2858                 case GL_TEXTURE_PRIORITY:
    2859                         *params = (GLfloat) tobj->priority;
    2860                         break;
    2861 #endif
    2862                 case GL_TEXTURE_BORDER_COLOR:
    2863                         params[0] = tobj->borderColor.r;
    2864                         params[1] = tobj->borderColor.g;
    2865                         params[2] = tobj->borderColor.b;
    2866                         params[3] = tobj->borderColor.a;
    2867                         break;
     2855        case GL_TEXTURE_WRAP_R:
     2856            *params = (GLfloat) tobj->wrapR;
     2857            break;
     2858        case GL_TEXTURE_PRIORITY:
     2859            *params = (GLfloat) tobj->priority;
     2860            break;
     2861#endif
     2862        case GL_TEXTURE_BORDER_COLOR:
     2863            params[0] = tobj->borderColor.r;
     2864            params[1] = tobj->borderColor.g;
     2865            params[2] = tobj->borderColor.b;
     2866            params[3] = tobj->borderColor.a;
     2867            break;
    28682868#ifdef CR_EXT_texture_filter_anisotropic
    2869                 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
    2870                         if (g->extensions.EXT_texture_filter_anisotropic) {
    2871                                 *params = (GLfloat) tobj->maxAnisotropy;
    2872                         }
    2873                         else {
    2874                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2875                                         "glGetTexParameterfv: invalid pname: 0x%x", pname);
    2876                                 return;
    2877                         }
    2878                         break;
     2869        case GL_TEXTURE_MAX_ANISOTROPY_EXT:
     2870            if (g->extensions.EXT_texture_filter_anisotropic) {
     2871                *params = (GLfloat) tobj->maxAnisotropy;
     2872            }
     2873            else {
     2874                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2875                    "glGetTexParameterfv: invalid pname: 0x%x", pname);
     2876                return;
     2877            }
     2878            break;
    28792879#endif
    28802880#ifdef CR_ARB_depth_texture
    2881                 case GL_DEPTH_TEXTURE_MODE_ARB:
    2882                         if (g->extensions.ARB_depth_texture) {
    2883                                 *params = (GLfloat) tobj->depthMode;
    2884                         }
    2885                         else {
    2886                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2887                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    2888                                 return;
    2889                         }
    2890                         break;
     2881        case GL_DEPTH_TEXTURE_MODE_ARB:
     2882            if (g->extensions.ARB_depth_texture) {
     2883                *params = (GLfloat) tobj->depthMode;
     2884            }
     2885            else {
     2886                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2887                    "glGetTexParameter: invalid pname: 0x%x", pname);
     2888                return;
     2889            }
     2890            break;
    28912891#endif
    28922892#ifdef CR_ARB_shadow
    2893                 case GL_TEXTURE_COMPARE_MODE_ARB:
    2894                         if (g->extensions.ARB_shadow) {
    2895                                 *params = (GLfloat) tobj->compareMode;
    2896                         }
    2897                         else {
    2898                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2899                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    2900                                 return;
    2901                         }
    2902                         break;
    2903                 case GL_TEXTURE_COMPARE_FUNC_ARB:
    2904                         if (g->extensions.ARB_shadow) {
    2905                                 *params = (GLfloat) tobj->compareFunc;
    2906                         }
    2907                         else {
    2908                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2909                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    2910                                 return;
    2911                         }
    2912                         break;
     2893        case GL_TEXTURE_COMPARE_MODE_ARB:
     2894            if (g->extensions.ARB_shadow) {
     2895                *params = (GLfloat) tobj->compareMode;
     2896            }
     2897            else {
     2898                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2899                    "glGetTexParameter: invalid pname: 0x%x", pname);
     2900                return;
     2901            }
     2902            break;
     2903        case GL_TEXTURE_COMPARE_FUNC_ARB:
     2904            if (g->extensions.ARB_shadow) {
     2905                *params = (GLfloat) tobj->compareFunc;
     2906            }
     2907            else {
     2908                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2909                    "glGetTexParameter: invalid pname: 0x%x", pname);
     2910                return;
     2911            }
     2912            break;
    29132913#endif
    29142914#ifdef CR_ARB_shadow_ambient
    2915                 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
    2916                         if (g->extensions.ARB_shadow_ambient) {
    2917                                 *params = (GLfloat) tobj->compareFailValue;
    2918                         }
    2919                         else {
    2920                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2921                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    2922                                 return;
    2923                         }
    2924                         break;
     2915        case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
     2916            if (g->extensions.ARB_shadow_ambient) {
     2917                *params = (GLfloat) tobj->compareFailValue;
     2918            }
     2919            else {
     2920                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2921                    "glGetTexParameter: invalid pname: 0x%x", pname);
     2922                return;
     2923            }
     2924            break;
    29252925#endif
    29262926#ifdef CR_SGIS_generate_mipmap
    2927                 case GL_GENERATE_MIPMAP_SGIS:
    2928                         if (g->extensions.SGIS_generate_mipmap) {
    2929                                 *params = (GLfloat) tobj->generateMipmap;
    2930                         }
    2931                         else {
    2932                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2933                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    2934                                 return;
    2935                         }
    2936                         break;
     2927        case GL_GENERATE_MIPMAP_SGIS:
     2928            if (g->extensions.SGIS_generate_mipmap) {
     2929                *params = (GLfloat) tobj->generateMipmap;
     2930            }
     2931            else {
     2932                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2933                    "glGetTexParameter: invalid pname: 0x%x", pname);
     2934                return;
     2935            }
     2936            break;
    29372937#endif
    29382938#ifdef CR_OPENGL_VERSION_1_2
    2939                 case GL_TEXTURE_MIN_LOD:
    2940                         *params = (GLfloat) tobj->minLod;
    2941                         break;
    2942                 case GL_TEXTURE_MAX_LOD:
    2943                         *params = (GLfloat) tobj->maxLod;
    2944                         break;
    2945                 case GL_TEXTURE_BASE_LEVEL:
    2946                         *params = (GLfloat) tobj->baseLevel;
    2947                         break;
    2948                 case GL_TEXTURE_MAX_LEVEL:
    2949                         *params = (GLfloat) tobj->maxLevel;
    2950                         break;
     2939        case GL_TEXTURE_MIN_LOD:
     2940            *params = (GLfloat) tobj->minLod;
     2941            break;
     2942        case GL_TEXTURE_MAX_LOD:
     2943            *params = (GLfloat) tobj->maxLod;
     2944            break;
     2945        case GL_TEXTURE_BASE_LEVEL:
     2946            *params = (GLfloat) tobj->baseLevel;
     2947            break;
     2948        case GL_TEXTURE_MAX_LEVEL:
     2949            *params = (GLfloat) tobj->maxLevel;
     2950            break;
    29512951#endif
    29522952#if 0
    2953                 case GL_TEXTURE_LOD_BIAS_EXT:
    2954                         /* XXX todo */
    2955                         *params = (GLfloat) tobj->lodBias;
    2956                         break;
    2957 #endif
    2958                 case GL_TEXTURE_RESIDENT:
    2959                         /* XXX todo */
    2960                         crWarning("glGetTexParameterfv GL_TEXTURE_RESIDENT is unimplemented");
    2961                         break;
    2962                 default:
    2963                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2964                                 "glGetTexParameterfv: invalid pname: %d", pname);
    2965                         return;
    2966         }
     2953        case GL_TEXTURE_LOD_BIAS_EXT:
     2954            /* XXX todo */
     2955            *params = (GLfloat) tobj->lodBias;
     2956            break;
     2957#endif
     2958            case GL_TEXTURE_RESIDENT:
     2959            /* XXX todo */
     2960            crWarning("glGetTexParameterfv GL_TEXTURE_RESIDENT is unimplemented");
     2961            break;
     2962        default:
     2963            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2964                "glGetTexParameterfv: invalid pname: %d", pname);
     2965            return;
     2966    }
    29672967}
    29682968
     
    29712971crStateGetTexParameteriv(GLenum target, GLenum pname, GLint *params)
    29722972{
    2973         CRContext *g = GetCurrentContext();
    2974         CRTextureObj *tobj;
    2975         CRTextureLevel *tl;
    2976 
    2977         if (g->current.inBeginEnd)
    2978         {
    2979                 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
    2980                                         "glGetTexParameter called in begin/end");
    2981                 return;
    2982         }
    2983 
    2984         crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
    2985         if (!tobj)
    2986         {
    2987                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    2988                         "glGetTexParameteriv: invalid target: 0x%x", target);
    2989                 return;
    2990         }
    2991 
    2992         switch (pname)
    2993         {
    2994                 case GL_TEXTURE_MAG_FILTER:
    2995                         *params = (GLint) tobj->magFilter;
    2996                         break;
    2997                 case GL_TEXTURE_MIN_FILTER:
    2998                         *params = (GLint) tobj->minFilter;
    2999                         break;
    3000                 case GL_TEXTURE_WRAP_S:
    3001                         *params = (GLint) tobj->wrapS;
    3002                         break;
    3003                 case GL_TEXTURE_WRAP_T:
    3004                         *params = (GLint) tobj->wrapT;
    3005                         break;
     2973    CRContext *g = GetCurrentContext();
     2974    CRTextureObj *tobj;
     2975    CRTextureLevel *tl;
     2976
     2977    if (g->current.inBeginEnd)
     2978    {
     2979        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
     2980                    "glGetTexParameter called in begin/end");
     2981        return;
     2982    }
     2983
     2984    crStateGetTextureObjectAndImage(g, target, 0, &tobj, &tl);
     2985    if (!tobj)
     2986    {
     2987        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     2988            "glGetTexParameteriv: invalid target: 0x%x", target);
     2989        return;
     2990    }
     2991
     2992    switch (pname)
     2993    {
     2994        case GL_TEXTURE_MAG_FILTER:
     2995            *params = (GLint) tobj->magFilter;
     2996            break;
     2997        case GL_TEXTURE_MIN_FILTER:
     2998            *params = (GLint) tobj->minFilter;
     2999            break;
     3000        case GL_TEXTURE_WRAP_S:
     3001            *params = (GLint) tobj->wrapS;
     3002            break;
     3003        case GL_TEXTURE_WRAP_T:
     3004            *params = (GLint) tobj->wrapT;
     3005            break;
    30063006#ifdef CR_OPENGL_VERSION_1_2
    3007                 case GL_TEXTURE_WRAP_R:
    3008                         *params = (GLint) tobj->wrapR;
    3009                         break;
    3010                 case GL_TEXTURE_PRIORITY:
    3011                         *params = (GLint) tobj->priority;
    3012                         break;
    3013 #endif
    3014                 case GL_TEXTURE_BORDER_COLOR:
    3015                         params[0] = (GLint) (tobj->borderColor.r * CR_MAXINT);
    3016                         params[1] = (GLint) (tobj->borderColor.g * CR_MAXINT);
    3017                         params[2] = (GLint) (tobj->borderColor.b * CR_MAXINT);
    3018                         params[3] = (GLint) (tobj->borderColor.a * CR_MAXINT);
    3019                         break;
     3007        case GL_TEXTURE_WRAP_R:
     3008            *params = (GLint) tobj->wrapR;
     3009            break;
     3010        case GL_TEXTURE_PRIORITY:
     3011            *params = (GLint) tobj->priority;
     3012            break;
     3013#endif
     3014        case GL_TEXTURE_BORDER_COLOR:
     3015            params[0] = (GLint) (tobj->borderColor.r * CR_MAXINT);
     3016            params[1] = (GLint) (tobj->borderColor.g * CR_MAXINT);
     3017            params[2] = (GLint) (tobj->borderColor.b * CR_MAXINT);
     3018            params[3] = (GLint) (tobj->borderColor.a * CR_MAXINT);
     3019            break;
    30203020#ifdef CR_OPENGL_VERSION_1_2
    3021                 case GL_TEXTURE_MIN_LOD:
    3022                         *params = (GLint) tobj->minLod;
    3023                         break;
    3024                 case GL_TEXTURE_MAX_LOD:
    3025                         *params = (GLint) tobj->maxLod;
    3026                         break;
    3027                 case GL_TEXTURE_BASE_LEVEL:
    3028                         *params = (GLint) tobj->baseLevel;
    3029                         break;
    3030                 case GL_TEXTURE_MAX_LEVEL:
    3031                         *params = (GLint) tobj->maxLevel;
    3032                         break;
     3021        case GL_TEXTURE_MIN_LOD:
     3022            *params = (GLint) tobj->minLod;
     3023            break;
     3024        case GL_TEXTURE_MAX_LOD:
     3025            *params = (GLint) tobj->maxLod;
     3026            break;
     3027        case GL_TEXTURE_BASE_LEVEL:
     3028            *params = (GLint) tobj->baseLevel;
     3029            break;
     3030        case GL_TEXTURE_MAX_LEVEL:
     3031            *params = (GLint) tobj->maxLevel;
     3032            break;
    30333033#endif
    30343034#ifdef CR_EXT_texture_filter_anisotropic
    3035                 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
    3036                         if (g->extensions.EXT_texture_filter_anisotropic) {
    3037                                 *params = (GLint) tobj->maxAnisotropy;
    3038                         }
    3039                         else {
    3040                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3041                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    3042                                 return;
    3043                         }
    3044                         break;
     3035        case GL_TEXTURE_MAX_ANISOTROPY_EXT:
     3036            if (g->extensions.EXT_texture_filter_anisotropic) {
     3037                *params = (GLint) tobj->maxAnisotropy;
     3038            }
     3039            else {
     3040                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3041                    "glGetTexParameter: invalid pname: 0x%x", pname);
     3042                return;
     3043            }
     3044            break;
    30453045#endif
    30463046#ifdef CR_ARB_depth_texture
    3047                 case GL_DEPTH_TEXTURE_MODE_ARB:
    3048                         if (g->extensions.ARB_depth_texture) {
    3049                                 *params = (GLint) tobj->depthMode;
    3050                         }
    3051                         else {
    3052                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3053                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    3054                                 return;
    3055                         }
    3056                         break;
     3047        case GL_DEPTH_TEXTURE_MODE_ARB:
     3048            if (g->extensions.ARB_depth_texture) {
     3049                *params = (GLint) tobj->depthMode;
     3050            }
     3051            else {
     3052                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3053                    "glGetTexParameter: invalid pname: 0x%x", pname);
     3054                return;
     3055            }
     3056            break;
    30573057#endif
    30583058#ifdef CR_ARB_shadow
    3059                 case GL_TEXTURE_COMPARE_MODE_ARB:
    3060                         if (g->extensions.ARB_shadow) {
    3061                                 *params = (GLint) tobj->compareMode;
    3062                         }
    3063                         else {
    3064                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3065                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    3066                                 return;
    3067                         }
    3068                         break;
    3069                 case GL_TEXTURE_COMPARE_FUNC_ARB:
    3070                         if (g->extensions.ARB_shadow) {
    3071                                 *params = (GLint) tobj->compareFunc;
    3072                         }
    3073                         else {
    3074                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3075                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    3076                                 return;
    3077                         }
    3078                         break;
     3059        case GL_TEXTURE_COMPARE_MODE_ARB:
     3060            if (g->extensions.ARB_shadow) {
     3061                *params = (GLint) tobj->compareMode;
     3062            }
     3063            else {
     3064                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3065                    "glGetTexParameter: invalid pname: 0x%x", pname);
     3066                return;
     3067            }
     3068            break;
     3069        case GL_TEXTURE_COMPARE_FUNC_ARB:
     3070            if (g->extensions.ARB_shadow) {
     3071                *params = (GLint) tobj->compareFunc;
     3072            }
     3073            else {
     3074                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3075                    "glGetTexParameter: invalid pname: 0x%x", pname);
     3076                return;
     3077            }
     3078            break;
    30793079#endif
    30803080#ifdef CR_ARB_shadow_ambient
    3081                 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
    3082                         if (g->extensions.ARB_shadow_ambient) {
    3083                                 *params = (GLint) tobj->compareFailValue;
    3084                         }
    3085                         else {
    3086                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3087                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    3088                                 return;
    3089                         }
    3090                         break;
     3081        case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
     3082            if (g->extensions.ARB_shadow_ambient) {
     3083                *params = (GLint) tobj->compareFailValue;
     3084            }
     3085            else {
     3086                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3087                    "glGetTexParameter: invalid pname: 0x%x", pname);
     3088                return;
     3089            }
     3090            break;
    30913091#endif
    30923092#ifdef CR_SGIS_generate_mipmap
    3093                 case GL_GENERATE_MIPMAP_SGIS:
    3094                         if (g->extensions.SGIS_generate_mipmap) {
    3095                                 *params = (GLint) tobj->generateMipmap;
    3096                         }
    3097                         else {
    3098                                 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3099                                         "glGetTexParameter: invalid pname: 0x%x", pname);
    3100                                 return;
    3101                         }
    3102                         break;
    3103 #endif
    3104                 case GL_TEXTURE_RESIDENT:
    3105                         /* XXX todo */
    3106                         crWarning("glGetTexParameteriv GL_TEXTURE_RESIDENT is unimplemented");
    3107                         break;
    3108                 default:
    3109                         crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
    3110                                 "glGetTexParameter: invalid pname: %d", pname);
    3111                         return;
    3112         }
     3093        case GL_GENERATE_MIPMAP_SGIS:
     3094            if (g->extensions.SGIS_generate_mipmap) {
     3095                *params = (GLint) tobj->generateMipmap;
     3096            }
     3097            else {
     3098                crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3099                    "glGetTexParameter: invalid pname: 0x%x", pname);
     3100                return;
     3101            }
     3102            break;
     3103#endif
     3104        case GL_TEXTURE_RESIDENT:
     3105            /* XXX todo */
     3106            crWarning("glGetTexParameteriv GL_TEXTURE_RESIDENT is unimplemented");
     3107            break;
     3108        default:
     3109            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
     3110                "glGetTexParameter: invalid pname: %d", pname);
     3111            return;
     3112    }
    31133113}
    31143114
     
    31163116void STATE_APIENTRY
    31173117crStatePrioritizeTextures(GLsizei n, const GLuint *textures,
    3118                                                                                                         const GLclampf *priorities)
    3119 {
    3120         UNUSED(n);
    3121         UNUSED(textures);
    3122         UNUSED(priorities);
    3123         /* TODO: */
    3124         return;
     3118                                                    const GLclampf *priorities)
     3119{
     3120    UNUSED(n);
     3121    UNUSED(textures);
     3122    UNUSED(priorities);
     3123    /* TODO: */
     3124    return;
    31253125}
    31263126
     
    31283128GLboolean STATE_APIENTRY
    31293129crStateAreTexturesResident(GLsizei n, const GLuint *textures,
    3130                                                                                                         GLboolean *residences)
    3131 {
    3132         UNUSED(n);
    3133         UNUSED(textures);
    3134         UNUSED(residences);
    3135         /* TODO: */
    3136         return GL_TRUE;
     3130                                                    GLboolean *residences)
     3131{
     3132    UNUSED(n);
     3133    UNUSED(textures);
     3134    UNUSED(residences);
     3135    /* TODO: */
     3136    return GL_TRUE;
    31373137}
    31383138
     
    31413141crStateIsTexture(GLuint texture)
    31423142{
    3143         CRContext *g = GetCurrentContext();
    3144         CRTextureObj *tobj;
    3145 
    3146         GET_TOBJ(tobj, g, texture);
    3147         return tobj != NULL;
    3148 }
     3143    CRContext *g = GetCurrentContext();
     3144    CRTextureObj *tobj;
     3145
     3146    GET_TOBJ(tobj, g, texture);
     3147    return tobj != NULL;
     3148}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette