mesa: Directly include mfeatures.h in files that perform feature tests.
[mesa.git] / src / mesa / main / texparam.c
index c4f249501878c530060d15c0f8bc949c1fc1a9fd..d2b8b5ca4ad828b3bada55af65a870003d9a1819 100644 (file)
 #include "main/context.h"
 #include "main/formats.h"
 #include "main/macros.h"
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
 #include "main/texcompress.h"
 #include "main/texparam.h"
 #include "main/teximage.h"
 #include "main/texstate.h"
-#include "shader/prog_instruction.h"
+#include "program/prog_instruction.h"
 
 
 /**
@@ -47,7 +49,7 @@
  * \return GL_TRUE if legal, GL_FALSE otherwise
  */
 static GLboolean 
-validate_texture_wrap_mode(GLcontext * ctx, GLenum target, GLenum wrap)
+validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
 {
    const struct gl_extensions * const e = & ctx->Extensions;
 
@@ -83,11 +85,11 @@ validate_texture_wrap_mode(GLcontext * ctx, GLenum target, GLenum wrap)
  * Only the glGetTexLevelParameter() functions accept proxy targets.
  */
 static struct gl_texture_object *
-get_texobj(GLcontext *ctx, GLenum target, GLboolean get)
+get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
 {
    struct gl_texture_unit *texUnit;
 
-   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
+   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "gl%sTexParameter(current unit)", get ? "Get" : "");
       return NULL;
@@ -178,7 +180,7 @@ set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
  * per-texture derived state gets recomputed.
  */
 static INLINE void
-flush(GLcontext *ctx, struct gl_texture_object *texObj)
+flush(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
    texObj->_Complete = GL_FALSE;
@@ -190,7 +192,7 @@ flush(GLcontext *ctx, struct gl_texture_object *texObj)
  * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
  */
 static GLboolean
-set_tex_parameteri(GLcontext *ctx,
+set_tex_parameteri(struct gl_context *ctx,
                    struct gl_texture_object *texObj,
                    GLenum pname, const GLint *params)
 {
@@ -291,17 +293,10 @@ set_tex_parameteri(GLcontext *ctx,
       return GL_TRUE;
 
    case GL_GENERATE_MIPMAP_SGIS:
-      if (ctx->Extensions.SGIS_generate_mipmap) {
-         if (texObj->GenerateMipmap != params[0]) {
-            flush(ctx, texObj);
-            texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
-            return GL_TRUE;
-         }
-         return GL_FALSE;
-      }
-      else {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
+      if (texObj->GenerateMipmap != params[0]) {
+        flush(ctx, texObj);
+        texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
+        return GL_TRUE;
       }
       return GL_FALSE;
 
@@ -358,7 +353,8 @@ set_tex_parameteri(GLcontext *ctx,
       if (ctx->Extensions.ARB_depth_texture &&
           (params[0] == GL_LUMINANCE ||
            params[0] == GL_INTENSITY ||
-           params[0] == GL_ALPHA)) {
+           params[0] == GL_ALPHA ||
+          (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED))) {
          if (texObj->DepthMode != params[0]) {
             flush(ctx, texObj);
             texObj->DepthMode = params[0];
@@ -371,7 +367,7 @@ set_tex_parameteri(GLcontext *ctx,
       }
       return GL_FALSE;
 
-#ifdef FEATURE_OES_draw_texture
+#if FEATURE_OES_draw_texture
    case GL_TEXTURE_CROP_RECT_OES:
       texObj->CropRect[0] = params[0];
       texObj->CropRect[1] = params[1];
@@ -436,7 +432,7 @@ set_tex_parameteri(GLcontext *ctx,
  * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
  */
 static GLboolean
-set_tex_parameterf(GLcontext *ctx,
+set_tex_parameterf(struct gl_context *ctx,
                    struct gl_texture_object *texObj,
                    GLenum pname, const GLfloat *params)
 {
@@ -604,7 +600,7 @@ _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
       }
       break;
 
-#ifdef FEATURE_OES_draw_texture
+#if FEATURE_OES_draw_texture
    case GL_TEXTURE_CROP_RECT_OES:
       {
          /* convert float params to int */
@@ -815,7 +811,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
+   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glGetTexLevelParameteriv(current unit)");
       return;
@@ -877,7 +873,17 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
          *params = img->Border;
          break;
       case GL_TEXTURE_RED_SIZE:
+         if (img->_BaseFormat == GL_RED) {
+            *params = _mesa_get_format_bits(texFormat, pname);
+           break;
+        }
+        /* FALLTHROUGH */
       case GL_TEXTURE_GREEN_SIZE:
+         if (img->_BaseFormat == GL_RG) {
+            *params = _mesa_get_format_bits(texFormat, pname);
+           break;
+        }
+        /* FALLTHROUGH */
       case GL_TEXTURE_BLUE_SIZE:
          if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
             *params = _mesa_get_format_bits(texFormat, pname);
@@ -940,6 +946,18 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
                         "glGetTexLevelParameter[if]v(pname)");
          }
          break;
+      case GL_TEXTURE_SHARED_SIZE:
+         if (ctx->VersionMajor >= 3) {
+            /* XXX return number of exponent bits for shared exponent texture
+             * formats, like GL_RGB9_E5.
+             */
+            *params = 0;
+         }
+         else {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetTexLevelParameter[if]v(pname)");
+         }
+         break;
 
       /* GL_ARB_texture_compression */
       case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
@@ -1114,11 +1132,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
            error = GL_TRUE;
          break;
       case GL_GENERATE_MIPMAP_SGIS:
-         if (ctx->Extensions.SGIS_generate_mipmap) {
-            *params = (GLfloat) obj->GenerateMipmap;
-         }
-        else 
-           error = GL_TRUE;
+        *params = (GLfloat) obj->GenerateMipmap;
          break;
       case GL_TEXTURE_COMPARE_MODE_ARB:
          if (ctx->Extensions.ARB_shadow) {
@@ -1148,7 +1162,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
         else 
            error = GL_TRUE;
          break;
-#ifdef FEATURE_OES_draw_texture
+#if FEATURE_OES_draw_texture
       case GL_TEXTURE_CROP_RECT_OES:
          params[0] = obj->CropRect[0];
          params[1] = obj->CropRect[1];
@@ -1279,12 +1293,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          }
          break;
       case GL_GENERATE_MIPMAP_SGIS:
-         if (ctx->Extensions.SGIS_generate_mipmap) {
-            *params = (GLint) obj->GenerateMipmap;
-         }
-         else {
-            error = GL_TRUE;
-         }
+        *params = (GLint) obj->GenerateMipmap;
          break;
       case GL_TEXTURE_COMPARE_MODE_ARB:
          if (ctx->Extensions.ARB_shadow) {
@@ -1318,7 +1327,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
             error = GL_TRUE;
          }
          break;
-#ifdef FEATURE_OES_draw_texture
+#if FEATURE_OES_draw_texture
       case GL_TEXTURE_CROP_RECT_OES:
          params[0] = obj->CropRect[0];
          params[1] = obj->CropRect[1];