mesa: print the Git SHA1 in GL_VERSION for ES1 and ES2.
[mesa.git] / src / mesa / main / texparam.c
index 0dec01729896f3623d9efcda3452a9c2fe8b149b..9abc503e3149915230dfdc3e91e78c3edc96290a 100644 (file)
 #include "main/context.h"
 #include "main/enums.h"
 #include "main/formats.h"
+#include "main/image.h"
 #include "main/macros.h"
 #include "main/mfeatures.h"
 #include "main/mtypes.h"
 #include "main/state.h"
 #include "main/texcompress.h"
+#include "main/texobj.h"
 #include "main/texparam.h"
 #include "main/teximage.h"
 #include "main/texstate.h"
-#include "main/texfetch.h"
 #include "program/prog_instruction.h"
 
 
@@ -56,23 +57,38 @@ validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
 {
    const struct gl_extensions * const e = & ctx->Extensions;
 
-   if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
-       (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
-      /* any texture target */
-      return GL_TRUE;
+   if (target == GL_TEXTURE_RECTANGLE_NV) {
+      if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
+          (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp))
+         return GL_TRUE;
    }
-   else if (target != GL_TEXTURE_RECTANGLE_NV &&
-           (wrap == GL_REPEAT ||
-            (wrap == GL_MIRRORED_REPEAT &&
-             e->ARB_texture_mirrored_repeat) ||
-            (wrap == GL_MIRROR_CLAMP_EXT &&
-             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
-            (wrap == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
-             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
-            (wrap == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
-             (e->EXT_texture_mirror_clamp)))) {
-      /* non-rectangle texture */
-      return GL_TRUE;
+   else if (target == GL_TEXTURE_EXTERNAL_OES) {
+      if (wrap == GL_CLAMP_TO_EDGE)
+         return GL_TRUE;
+   }
+   else {
+      switch (wrap) {
+      case GL_CLAMP:
+      case GL_REPEAT:
+      case GL_CLAMP_TO_EDGE:
+      case GL_MIRRORED_REPEAT:
+         return GL_TRUE;
+      case GL_CLAMP_TO_BORDER:
+         if (e->ARB_texture_border_clamp)
+            return GL_TRUE;
+         break;
+      case GL_MIRROR_CLAMP_EXT:
+      case GL_MIRROR_CLAMP_TO_EDGE_EXT:
+         if (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
+            return GL_TRUE;
+         break;
+      case GL_MIRROR_CLAMP_TO_BORDER_EXT:
+         if (e->EXT_texture_mirror_clamp)
+            return GL_TRUE;
+         break;
+      default:
+         break;
+      }
    }
 
    _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
@@ -129,6 +145,11 @@ get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
          return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
       }
       break;
+   case GL_TEXTURE_EXTERNAL_OES:
+      if (ctx->Extensions.OES_EGL_image_external) {
+         return texUnit->CurrentTex[TEXTURE_EXTERNAL_INDEX];
+      }
+      break;
    default:
       ;
    }
@@ -182,7 +203,7 @@ set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
  * This is called just prior to changing any texture object state which
  * will not effect texture completeness.
  */
-static INLINE void
+static inline void
 flush(struct gl_context *ctx)
 {
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
@@ -191,17 +212,16 @@ flush(struct gl_context *ctx)
 
 /**
  * This is called just prior to changing any texture object state which
- * can effect texture completeness (texture base level, max level,
- * minification filter).
+ * can effect texture completeness (texture base level, max level).
  * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
  * state flag and then mark the texture object as 'incomplete' so that any
  * per-texture derived state gets recomputed.
  */
-static INLINE void
+static inline void
 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-   texObj->_Complete = GL_FALSE;
+   _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
 }
 
 
@@ -221,15 +241,16 @@ set_tex_parameteri(struct gl_context *ctx,
       switch (params[0]) {
       case GL_NEAREST:
       case GL_LINEAR:
-         incomplete(ctx, texObj);
+         flush(ctx);
          texObj->Sampler.MinFilter = params[0];
          return GL_TRUE;
       case GL_NEAREST_MIPMAP_NEAREST:
       case GL_LINEAR_MIPMAP_NEAREST:
       case GL_NEAREST_MIPMAP_LINEAR:
       case GL_LINEAR_MIPMAP_LINEAR:
-         if (texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
-            incomplete(ctx, texObj);
+         if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
+             texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
+            flush(ctx);
             texObj->Sampler.MinFilter = params[0];
             return GL_TRUE;
          }
@@ -309,6 +330,8 @@ set_tex_parameteri(struct gl_context *ctx,
       return GL_TRUE;
 
    case GL_GENERATE_MIPMAP_SGIS:
+      if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
+         goto invalid_param;
       if (texObj->GenerateMipmap != params[0]) {
          /* no flush() */
         texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
@@ -396,12 +419,11 @@ set_tex_parameteri(struct gl_context *ctx,
             return GL_FALSE;
          }
          ASSERT(comp < 4);
-         if (swz >= 0) {
-            flush(ctx);
-            texObj->Swizzle[comp] = params[0];
-            set_swizzle_component(&texObj->_Swizzle, comp, swz);
-            return GL_TRUE;
-         }
+
+         flush(ctx);
+         texObj->Swizzle[comp] = params[0];
+         set_swizzle_component(&texObj->_Swizzle, comp, swz);
+         return GL_TRUE;
       }
       goto invalid_pname;
 
@@ -432,7 +454,6 @@ set_tex_parameteri(struct gl_context *ctx,
            if (texObj->Sampler.sRGBDecode != decode) {
               flush(ctx);
               texObj->Sampler.sRGBDecode = decode;
-              _mesa_update_fetch_functions(texObj);
            }
            return GL_TRUE;
         }
@@ -536,13 +557,10 @@ set_tex_parameterf(struct gl_context *ctx,
 
    case GL_TEXTURE_LOD_BIAS:
       /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
-      if (ctx->Extensions.EXT_texture_lod_bias) {
-         if (texObj->Sampler.LodBias != params[0]) {
-            flush(ctx);
-            texObj->Sampler.LodBias = params[0];
-            return GL_TRUE;
-         }
-         return GL_FALSE;
+      if (texObj->Sampler.LodBias != params[0]) {
+        flush(ctx);
+        texObj->Sampler.LodBias = params[0];
+        return GL_TRUE;
       }
       break;
 
@@ -603,6 +621,17 @@ _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
          need_update = set_tex_parameteri(ctx, texObj, pname, p);
       }
       break;
+   case GL_TEXTURE_SWIZZLE_R_EXT:
+   case GL_TEXTURE_SWIZZLE_G_EXT:
+   case GL_TEXTURE_SWIZZLE_B_EXT:
+   case GL_TEXTURE_SWIZZLE_A_EXT:
+      {
+         GLint p[4];
+         p[0] = (GLint) param;
+         p[1] = p[2] = p[3] = 0;
+         need_update = set_tex_parameteri(ctx, texObj, pname, p);
+      }
+      break;
    default:
       {
          /* this will generate an error if pname is illegal */
@@ -668,6 +697,22 @@ _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
       break;
 #endif
 
+   case GL_TEXTURE_SWIZZLE_R_EXT:
+   case GL_TEXTURE_SWIZZLE_G_EXT:
+   case GL_TEXTURE_SWIZZLE_B_EXT:
+   case GL_TEXTURE_SWIZZLE_A_EXT:
+   case GL_TEXTURE_SWIZZLE_RGBA_EXT:
+      {
+         GLint p[4] = {0, 0, 0, 0};
+         p[0] = (GLint) params[0];
+         if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
+            p[1] = (GLint) params[1];
+            p[2] = (GLint) params[2];
+            p[3] = (GLint) params[3];
+         }
+         need_update = set_tex_parameteri(ctx, texObj, pname, p);
+      }
+      break;
    default:
       /* this will generate an error if pname is illegal */
       need_update = set_tex_parameterf(ctx, texObj, pname, params);
@@ -840,8 +885,6 @@ _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
 }
 
 
-
-
 void GLAPIENTRY
 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
                               GLenum pname, GLfloat *params )
@@ -937,61 +980,29 @@ _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);
-         else
-            *params = 0;
-         break;
       case GL_TEXTURE_ALPHA_SIZE:
-         if (img->_BaseFormat == GL_ALPHA ||
-             img->_BaseFormat == GL_LUMINANCE_ALPHA ||
-             img->_BaseFormat == GL_RGBA)
+         if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
             *params = _mesa_get_format_bits(texFormat, pname);
          else
             *params = 0;
          break;
       case GL_TEXTURE_INTENSITY_SIZE:
-         if (img->_BaseFormat != GL_INTENSITY)
-            *params = 0;
-         else {
-            *params = _mesa_get_format_bits(texFormat, pname);
-            if (*params == 0) {
-               /* intensity probably stored as rgb texture */
-               *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
-                              _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
-            }
-         }
-         break;
       case GL_TEXTURE_LUMINANCE_SIZE:
-         if (img->_BaseFormat != GL_LUMINANCE &&
-             img->_BaseFormat != GL_LUMINANCE_ALPHA)
-            *params = 0;
-         else {
+         if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
             *params = _mesa_get_format_bits(texFormat, pname);
             if (*params == 0) {
-               /* luminance probably stored as rgb texture */
-               *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
-                              _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
+               /* intensity or luminance is probably stored as RGB[A] */
+               *params = MIN2(_mesa_get_format_bits(texFormat,
+                                                    GL_TEXTURE_RED_SIZE),
+                              _mesa_get_format_bits(texFormat,
+                                                    GL_TEXTURE_GREEN_SIZE));
             }
          }
-         break;
-      case GL_TEXTURE_INDEX_SIZE_EXT:
-         if (img->_BaseFormat == GL_COLOR_INDEX)
-            *params = _mesa_get_format_bits(texFormat, pname);
-         else
+         else {
             *params = 0;
+         }
          break;
       case GL_TEXTURE_DEPTH_SIZE_ARB:
          if (!ctx->Extensions.ARB_depth_texture)
@@ -1029,46 +1040,18 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
 
       /* GL_ARB_texture_float */
       case GL_TEXTURE_RED_TYPE_ARB:
-         if (!ctx->Extensions.ARB_texture_float)
-            goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
-         break;
       case GL_TEXTURE_GREEN_TYPE_ARB:
-         if (!ctx->Extensions.ARB_texture_float)
-            goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
-         break;
       case GL_TEXTURE_BLUE_TYPE_ARB:
-         if (!ctx->Extensions.ARB_texture_float)
-            goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
-         break;
       case GL_TEXTURE_ALPHA_TYPE_ARB:
-         if (!ctx->Extensions.ARB_texture_float)
-            goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
-         break;
       case GL_TEXTURE_LUMINANCE_TYPE_ARB:
-         if (!ctx->Extensions.ARB_texture_float)
-            goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
-         break;
       case GL_TEXTURE_INTENSITY_TYPE_ARB:
-         if (!ctx->Extensions.ARB_texture_float)
-            goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
-         break;
       case GL_TEXTURE_DEPTH_TYPE_ARB:
          if (!ctx->Extensions.ARB_texture_float)
             goto invalid_pname;
-         *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
-            _mesa_get_format_datatype(texFormat) : GL_NONE;
+        if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
+           *params = _mesa_get_format_datatype(texFormat);
+        else
+           *params = GL_NONE;
          break;
 
       default:
@@ -1115,17 +1098,15 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
          *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
          break;
       case GL_TEXTURE_BORDER_COLOR:
-         if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
+         if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
             _mesa_update_state_locked(ctx);
-         if(ctx->Color._ClampFragmentColor)
-         {
+         if (ctx->Color._ClampFragmentColor) {
             params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
             params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
             params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
             params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
          }
-         else
-         {
+         else {
             params[0] = obj->Sampler.BorderColor.f[0];
             params[1] = obj->Sampler.BorderColor.f[1];
             params[2] = obj->Sampler.BorderColor.f[2];
@@ -1133,8 +1114,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
          }
          break;
       case GL_TEXTURE_RESIDENT:
-         *params = ctx->Driver.IsTextureResident ?
-            ctx->Driver.IsTextureResident(ctx, obj) : 1.0F;
+         *params = 1.0F;
          break;
       case GL_TEXTURE_PRIORITY:
          *params = obj->Priority;
@@ -1180,8 +1160,6 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
          *params = (GLfloat) obj->Sampler.DepthMode;
          break;
       case GL_TEXTURE_LOD_BIAS:
-         if (!ctx->Extensions.EXT_texture_lod_bias)
-            goto invalid_pname;
          *params = obj->Sampler.LodBias;
          break;
 #if FEATURE_OES_draw_texture
@@ -1220,6 +1198,12 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
          *params = (GLfloat) obj->Sampler.CubeMapSeamless;
          break;
 
+      case GL_TEXTURE_IMMUTABLE_FORMAT:
+         if (!ctx->Extensions.ARB_texture_storage)
+            goto invalid_pname;
+         *params = (GLfloat) obj->Immutable;
+         break;
+
       default:
          goto invalid_pname;
    }
@@ -1241,27 +1225,27 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-    obj = get_texobj(ctx, target, GL_TRUE);
-    if (!obj)
-       return;
+   obj = get_texobj(ctx, target, GL_TRUE);
+   if (!obj)
+      return;
 
    _mesa_lock_texture(ctx, obj);
    switch (pname) {
       case GL_TEXTURE_MAG_FILTER:
          *params = (GLint) obj->Sampler.MagFilter;
-         break;;
+         break;
       case GL_TEXTURE_MIN_FILTER:
          *params = (GLint) obj->Sampler.MinFilter;
-         break;;
+         break;
       case GL_TEXTURE_WRAP_S:
          *params = (GLint) obj->Sampler.WrapS;
-         break;;
+         break;
       case GL_TEXTURE_WRAP_T:
          *params = (GLint) obj->Sampler.WrapT;
-         break;;
+         break;
       case GL_TEXTURE_WRAP_R:
          *params = (GLint) obj->Sampler.WrapR;
-         break;;
+         break;
       case GL_TEXTURE_BORDER_COLOR:
          {
             GLfloat b[4];
@@ -1274,26 +1258,25 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
             params[2] = FLOAT_TO_INT(b[2]);
             params[3] = FLOAT_TO_INT(b[3]);
          }
-         break;;
+         break;
       case GL_TEXTURE_RESIDENT:
-         *params = ctx->Driver.IsTextureResident ?
-            ctx->Driver.IsTextureResident(ctx, obj) : 1;
-         break;;
+         *params = 1;
+         break;
       case GL_TEXTURE_PRIORITY:
          *params = FLOAT_TO_INT(obj->Priority);
-         break;;
+         break;
       case GL_TEXTURE_MIN_LOD:
          *params = (GLint) obj->Sampler.MinLod;
-         break;;
+         break;
       case GL_TEXTURE_MAX_LOD:
          *params = (GLint) obj->Sampler.MaxLod;
-         break;;
+         break;
       case GL_TEXTURE_BASE_LEVEL:
          *params = obj->BaseLevel;
-         break;;
+         break;
       case GL_TEXTURE_MAX_LEVEL:
          *params = obj->MaxLevel;
-         break;;
+         break;
       case GL_TEXTURE_MAX_ANISOTROPY_EXT:
          if (!ctx->Extensions.EXT_texture_filter_anisotropic)
             goto invalid_pname;
@@ -1323,8 +1306,6 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          *params = (GLint) obj->Sampler.DepthMode;
          break;
       case GL_TEXTURE_LOD_BIAS:
-         if (!ctx->Extensions.EXT_texture_lod_bias)
-            goto invalid_pname;
          *params = (GLint) obj->Sampler.LodBias;
          break;
 #if FEATURE_OES_draw_texture
@@ -1356,6 +1337,18 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          *params = (GLint) obj->Sampler.CubeMapSeamless;
          break;
 
+      case GL_TEXTURE_IMMUTABLE_FORMAT:
+         if (!ctx->Extensions.ARB_texture_storage)
+            goto invalid_pname;
+         *params = (GLint) obj->Immutable;
+         break;
+
+      case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
+         if (!ctx->Extensions.OES_EGL_image_external)
+            goto invalid_pname;
+         *params = obj->RequiredTextureImageUnits;
+         break;
+
       default:
          goto invalid_pname;
    }
@@ -1379,6 +1372,8 @@ _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    texObj = get_texobj(ctx, target, GL_TRUE);
+   if (!texObj)
+      return;
    
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
@@ -1399,6 +1394,8 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    texObj = get_texobj(ctx, target, GL_TRUE);
+   if (!texObj)
+      return;
    
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR: