glapi: Move to src/mapi/.
[mesa.git] / src / mesa / main / texenv.c
index 4d511f2f7ed8b5389dc1ab0ccd6dec70533a08ee..4442fb8cf8e9877a55bc085d313bcdb2a1d6f3ce 100644 (file)
@@ -35,6 +35,7 @@
 #include "main/enums.h"
 #include "main/macros.h"
 #include "main/texenv.h"
+#include "main/texstate.h"
 
 
 #define TE_ERROR(errCode, msg, value)                          \
@@ -466,7 +467,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
       return;
    }
 
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   texUnit = _mesa_get_current_tex_unit(ctx);
 
    if (target == GL_TEXTURE_ENV) {
       switch (pname) {
@@ -597,7 +598,10 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 void GLAPIENTRY
 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
 {
-   _mesa_TexEnvfv( target, pname, &param );
+   GLfloat p[4];
+   p[0] = param;
+   p[1] = p[2] = p[3] = 0.0;
+   _mesa_TexEnvfv( target, pname, p );
 }
 
 
@@ -793,7 +797,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
       return;
    }
 
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   texUnit = _mesa_get_current_tex_unit(ctx);
 
    if (target == GL_TEXTURE_ENV) {
       if (pname == GL_TEXTURE_ENV_COLOR) {
@@ -857,7 +861,7 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
       return;
    }
 
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   texUnit = _mesa_get_current_tex_unit(ctx);
 
    if (target == GL_TEXTURE_ENV) {
       if (pname == GL_TEXTURE_ENV_COLOR) {
@@ -908,12 +912,26 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
    }
 }
 
-/* why does ATI_envmap_bumpmap require new entrypoints? Should just
-   reuse TexEnv ones... */
+
+/**
+ * Why does ATI_envmap_bumpmap require new entrypoints? Should just
+ * reuse TexEnv ones...
+ */
 void GLAPIENTRY
 _mesa_TexBumpParameterivATI( GLenum pname, const GLint *param )
 {
    GLfloat p[4];
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!ctx->Extensions.ATI_envmap_bumpmap) {
+      /* This isn't an "official" error case, but let's tell the user
+       * that something's wrong.
+       */
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBumpParameterivATI");
+      return;
+   }
+
    if (pname == GL_BUMP_ROT_MATRIX_ATI) {
       /* hope that conversion is correct here */
       p[0] = INT_TO_FLOAT( param[0] );
@@ -923,11 +941,12 @@ _mesa_TexBumpParameterivATI( GLenum pname, const GLint *param )
    }
    else {
       p[0] = (GLfloat) param[0];
-      p[1] = p[2] = p[3] = 0;  /* init to zero, just to be safe */
+      p[1] = p[2] = p[3] = 0.0F;  /* init to zero, just to be safe */
    }
    _mesa_TexBumpParameterfvATI( pname, p );
 }
 
+
 void GLAPIENTRY
 _mesa_TexBumpParameterfvATI( GLenum pname, const GLfloat *param )
 {
@@ -935,8 +954,12 @@ _mesa_TexBumpParameterfvATI( GLenum pname, const GLfloat *param )
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   /* should return error if extension not supported? */
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   if (!ctx->Extensions.ATI_envmap_bumpmap) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBumpParameterfvATI");
+      return;
+   }
+
+   texUnit = _mesa_get_current_tex_unit(ctx);
 
    if (pname == GL_BUMP_ROT_MATRIX_ATI) {
       if (TEST_EQ_4V(param, texUnit->RotMatrix))
@@ -955,17 +978,21 @@ _mesa_TexBumpParameterfvATI( GLenum pname, const GLfloat *param )
    }
 }
 
+
 void GLAPIENTRY
 _mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param )
 {
    const struct gl_texture_unit *texUnit;
-   GLint i;
-   GLint temp = 0;
+   GLuint i;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   /* should return error if extension not supported? */
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   if (!ctx->Extensions.ATI_envmap_bumpmap) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexBumpParameterivATI");
+      return;
+   }
+
+   texUnit = _mesa_get_current_tex_unit(ctx);
 
    if (pname == GL_BUMP_ROT_MATRIX_SIZE_ATI) {
       /* spec leaves open to support larger matrices.
@@ -982,12 +1009,13 @@ _mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param )
       param[3] = FLOAT_TO_INT(texUnit->RotMatrix[3]);
    }
    else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) {
+      GLint count = 0;
       for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
          if (ctx->Const.SupportedBumpUnits & (1 << i)) {
-            temp++;
+            count++;
          }
       }
-      *param = temp;
+      *param = count;
    }
    else if (pname == GL_BUMP_TEX_UNITS_ATI) {
       for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
@@ -1002,23 +1030,27 @@ _mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param )
    }
 }
 
+
 void GLAPIENTRY
 _mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param )
 {
    const struct gl_texture_unit *texUnit;
-   GLint i;
-   GLint temp = 0;
+   GLuint i;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   /* should return error if extension not supported? */
-   texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   if (!ctx->Extensions.ATI_envmap_bumpmap) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexBumpParameterfvATI");
+      return;
+   }
+
+   texUnit = _mesa_get_current_tex_unit(ctx);
 
    if (pname == GL_BUMP_ROT_MATRIX_SIZE_ATI) {
       /* spec leaves open to support larger matrices.
          Don't think anyone would ever want to use it
          (and apps might not understand it) so hardcode this. */
-      *param = (GLfloat) 4;
+      *param = 4.0F;
    }
    else if (pname == GL_BUMP_ROT_MATRIX_ATI) {
       param[0] = texUnit->RotMatrix[0];
@@ -1027,12 +1059,13 @@ _mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param )
       param[3] = texUnit->RotMatrix[3];
    }
    else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) {
+      GLint count = 0;
       for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
          if (ctx->Const.SupportedBumpUnits & (1 << i)) {
-            temp++;
+            count++;
          }
       }
-      *param = (GLfloat) temp;
+      *param = (GLfloat) count;
    }
    else if (pname == GL_BUMP_TEX_UNITS_ATI) {
       for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
@@ -1046,4 +1079,3 @@ _mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param )
       return;
    }
 }
-