mesa: remove redundant error check
[mesa.git] / src / mesa / main / texparam.c
index 614c1eef504b461a18c620338677a66a7e6c2e27..1059a4cb5eea52d9a3300770f9ae8620a330aded 100644 (file)
@@ -72,7 +72,7 @@ validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
       break;
 
    case GL_CLAMP_TO_BORDER:
-      supported = is_desktop_gl && e->ARB_texture_border_clamp
+      supported = ctx->API != API_OPENGLES && e->ARB_texture_border_clamp
          && (target != GL_TEXTURE_EXTERNAL_OES);
       break;
 
@@ -153,18 +153,13 @@ get_texobj_by_target(struct gl_context *ctx, GLenum target, GLboolean get)
  * Only the glGetTexLevelParameter() functions accept proxy targets.
  */
 static struct gl_texture_object *
-get_texobj_by_name(struct gl_context *ctx, GLuint texture, GLboolean get)
+get_texobj_by_name(struct gl_context *ctx, GLuint texture, const char *name)
 {
    struct gl_texture_object *texObj;
 
-   texObj = _mesa_lookup_texture(ctx, texture);
-   if (!texObj) {
-      /*
-       * User passed a non-generated name.
-       * Throw the error in the caller.
-       */
+   texObj = _mesa_lookup_texture_err(ctx, texture, name);
+   if (!texObj)
       return NULL;
-   }
 
    switch (texObj->Target) {
    case GL_TEXTURE_1D:
@@ -179,8 +174,7 @@ get_texobj_by_name(struct gl_context *ctx, GLuint texture, GLboolean get)
    case GL_TEXTURE_RECTANGLE:
       return texObj;
    default:
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "gl%sTextureParameter(target)", get ? "Get" : "");
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", name);
       return NULL;
    }
 
@@ -233,27 +227,27 @@ set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
 static inline void
 flush(struct gl_context *ctx)
 {
-   FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+   FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
 }
 
 
 /**
  * This is called just prior to changing any texture object state which
  * could affect texture completeness (texture base level, max level).
- * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
+ * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE_OBJECT
  * state flag and then mark the texture object as 'incomplete' so that any
  * per-texture derived state gets recomputed.
  */
 static inline void
 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
-   FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+   FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
    _mesa_dirty_texobj(ctx, texObj);
 }
 
 
-static GLboolean
-target_allows_setting_sampler_parameters(GLenum target)
+GLboolean
+_mesa_target_allows_setting_sampler_parameters(GLenum target)
 {
    switch (target) {
    case GL_TEXTURE_2D_MULTISAMPLE:
@@ -277,9 +271,22 @@ set_tex_parameteri(struct gl_context *ctx,
 {
    const char *suffix = dsa ? "ture" : "";
 
+   if (texObj->HandleAllocated) {
+      /* The ARB_bindless_texture spec says:
+       *
+       * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
+       * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
+       * functions defined in terms of these, if the texture object to be
+       * modified is referenced by one or more texture or image handles."
+       */
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glTex%sParameter(immutable texture)", suffix);
+      return GL_FALSE;
+   }
+
    switch (pname) {
    case GL_TEXTURE_MIN_FILTER:
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.MinFilter == params[0])
@@ -307,7 +314,7 @@ set_tex_parameteri(struct gl_context *ctx,
       return GL_FALSE;
 
    case GL_TEXTURE_MAG_FILTER:
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.MagFilter == params[0])
@@ -324,7 +331,7 @@ set_tex_parameteri(struct gl_context *ctx,
       return GL_FALSE;
 
    case GL_TEXTURE_WRAP_S:
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.WrapS == params[0])
@@ -337,7 +344,7 @@ set_tex_parameteri(struct gl_context *ctx,
       return GL_FALSE;
 
    case GL_TEXTURE_WRAP_T:
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.WrapT == params[0])
@@ -350,7 +357,7 @@ set_tex_parameteri(struct gl_context *ctx,
       return GL_FALSE;
 
    case GL_TEXTURE_WRAP_R:
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.WrapR == params[0])
@@ -438,7 +445,7 @@ set_tex_parameteri(struct gl_context *ctx,
       if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
           || _mesa_is_gles3(ctx)) {
 
-         if (!target_allows_setting_sampler_parameters(texObj->Target))
+         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
             goto invalid_enum;
 
          if (texObj->Sampler.CompareMode == params[0])
@@ -457,7 +464,7 @@ set_tex_parameteri(struct gl_context *ctx,
       if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
           || _mesa_is_gles3(ctx)) {
 
-         if (!target_allows_setting_sampler_parameters(texObj->Target))
+         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
             goto invalid_enum;
 
          if (texObj->Sampler.CompareFunc == params[0])
@@ -568,11 +575,10 @@ set_tex_parameteri(struct gl_context *ctx,
       goto invalid_pname;
 
    case GL_TEXTURE_SRGB_DECODE_EXT:
-      if (_mesa_is_desktop_gl(ctx)
-          && ctx->Extensions.EXT_texture_sRGB_decode) {
+      if (ctx->Extensions.EXT_texture_sRGB_decode) {
          GLenum decode = params[0];
 
-         if (!target_allows_setting_sampler_parameters(texObj->Target))
+         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
             goto invalid_enum;
 
         if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
@@ -590,7 +596,7 @@ set_tex_parameteri(struct gl_context *ctx,
           && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
          GLenum param = params[0];
 
-         if (!target_allows_setting_sampler_parameters(texObj->Target))
+         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
             goto invalid_enum;
 
          if (param != GL_TRUE && param != GL_FALSE) {
@@ -641,12 +647,25 @@ set_tex_parameterf(struct gl_context *ctx,
 {
    const char *suffix = dsa ? "ture" : "";
 
+   if (texObj->HandleAllocated) {
+      /* The ARB_bindless_texture spec says:
+       *
+       * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
+       * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
+       * functions defined in terms of these, if the texture object to be
+       * modified is referenced by one or more texture or image handles."
+       */
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glTex%sParameter(immutable texture)", suffix);
+      return GL_FALSE;
+   }
+
    switch (pname) {
    case GL_TEXTURE_MIN_LOD:
       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
          goto invalid_pname;
 
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.MinLod == params[0])
@@ -659,7 +678,7 @@ set_tex_parameterf(struct gl_context *ctx,
       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
          goto invalid_pname;
 
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.MaxLod == params[0])
@@ -678,7 +697,7 @@ set_tex_parameterf(struct gl_context *ctx,
 
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       if (ctx->Extensions.EXT_texture_filter_anisotropic) {
-         if (!target_allows_setting_sampler_parameters(texObj->Target))
+         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
             goto invalid_enum;
 
          if (texObj->Sampler.MaxAnisotropy == params[0])
@@ -706,7 +725,7 @@ set_tex_parameterf(struct gl_context *ctx,
       if (_mesa_is_gles(ctx))
          goto invalid_pname;
 
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       if (texObj->Sampler.LodBias != params[0]) {
@@ -717,10 +736,19 @@ set_tex_parameterf(struct gl_context *ctx,
       break;
 
    case GL_TEXTURE_BORDER_COLOR:
-      if (!_mesa_is_desktop_gl(ctx))
+      /* Border color exists in desktop OpenGL since 1.0 for GL_CLAMP.  In
+       * OpenGL ES 2.0+, it only exists in when GL_OES_texture_border_clamp is
+       * enabled.  It is never available in OpenGL ES 1.x.
+       *
+       * FIXME: Every driver that supports GLES2 has this extension.  Elide
+       * the check?
+       */
+      if (ctx->API == API_OPENGLES ||
+          (ctx->API == API_OPENGLES2 &&
+           !ctx->Extensions.ARB_texture_border_clamp))
          goto invalid_pname;
 
-      if (!target_allows_setting_sampler_parameters(texObj->Target))
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
          goto invalid_enum;
 
       flush(ctx);
@@ -807,7 +835,7 @@ _mesa_texture_parameterf(struct gl_context *ctx,
    }
 
    if (ctx->Driver.TexParameter && need_update) {
-      ctx->Driver.TexParameter(ctx, texObj, pname, &param);
+      ctx->Driver.TexParameter(ctx, texObj, pname);
    }
 }
 
@@ -874,7 +902,7 @@ _mesa_texture_parameterfv(struct gl_context *ctx,
    }
 
    if (ctx->Driver.TexParameter && need_update) {
-      ctx->Driver.TexParameter(ctx, texObj, pname, params);
+      ctx->Driver.TexParameter(ctx, texObj, pname);
    }
 }
 
@@ -919,8 +947,7 @@ _mesa_texture_parameteri(struct gl_context *ctx,
    }
 
    if (ctx->Driver.TexParameter && need_update) {
-      GLfloat fparam = (GLfloat) param;
-      ctx->Driver.TexParameter(ctx, texObj, pname, &fparam);
+      ctx->Driver.TexParameter(ctx, texObj, pname);
    }
 }
 
@@ -964,15 +991,7 @@ _mesa_texture_parameteriv(struct gl_context *ctx,
    }
 
    if (ctx->Driver.TexParameter && need_update) {
-      GLfloat fparams[4];
-      fparams[0] = INT_TO_FLOAT(params[0]);
-      if (pname == GL_TEXTURE_BORDER_COLOR ||
-          pname == GL_TEXTURE_CROP_RECT_OES) {
-         fparams[1] = INT_TO_FLOAT(params[1]);
-         fparams[2] = INT_TO_FLOAT(params[2]);
-         fparams[3] = INT_TO_FLOAT(params[3]);
-      }
-      ctx->Driver.TexParameter(ctx, texObj, pname, fparams);
+      ctx->Driver.TexParameter(ctx, texObj, pname);
    }
 }
 
@@ -983,7 +1002,17 @@ _mesa_texture_parameterIiv(struct gl_context *ctx,
 {
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
-      FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+      if (texObj->HandleAllocated) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glTextureParameterIiv(immutable texture)");
+         return;
+      }
+
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameterIiv(texture)");
+         return;
+      }
+      FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
       /* set the integer-valued border color */
       COPY_4V(texObj->Sampler.BorderColor.i, params);
       break;
@@ -1001,7 +1030,17 @@ _mesa_texture_parameterIuiv(struct gl_context *ctx,
 {
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
-      FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+      if (texObj->HandleAllocated) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glTextureParameterIuiv(immutable texture)");
+         return;
+      }
+
+      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameterIuiv(texture)");
+         return;
+      }
+      FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
       /* set the unsigned integer-valued border color */
       COPY_4V(texObj->Sampler.BorderColor.ui, params);
       break;
@@ -1108,12 +1147,9 @@ _mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfv(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterfv");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
 }
@@ -1124,12 +1160,9 @@ _mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterf(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterf");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterf(ctx, texObj, pname, param, true);
 }
@@ -1140,12 +1173,9 @@ _mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteri(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glTextureParameteri");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameteri(ctx, texObj, pname, param, true);
 }
@@ -1157,12 +1187,9 @@ _mesa_TextureParameteriv(GLuint texture, GLenum pname,
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriv(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glTextureParameteriv");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
 }
@@ -1174,13 +1201,9 @@ _mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glTextureParameterIiv(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIiv");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
 }
@@ -1191,20 +1214,16 @@ _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glTextureParameterIuiv(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
 }
 
-static GLboolean
-legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
-                                     bool dsa)
+GLboolean
+_mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
+                                           bool dsa)
 {
    /* Common targets for desktop GL and GLES 3.1. */
    switch (target) {
@@ -1223,6 +1242,28 @@ legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
    case GL_TEXTURE_2D_MULTISAMPLE:
    case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
       return ctx->Extensions.ARB_texture_multisample;
+   case GL_TEXTURE_BUFFER:
+      /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
+       * but not in earlier versions that expose ARB_texture_buffer_object.
+       *
+       * From the ARB_texture_buffer_object spec:
+       * "(7) Do buffer textures support texture parameters (TexParameter) or
+       *      queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
+       *
+       *    RESOLVED:  No. [...] Note that the spec edits above don't add
+       *    explicit error language for any of these cases.  That is because
+       *    each of the functions enumerate the set of valid <target>
+       *    parameters.  Not editing the spec to allow TEXTURE_BUFFER_ARB in
+       *    these cases means that target is not legal, and an INVALID_ENUM
+       *    error should be generated."
+       *
+       * From the OpenGL 3.1 spec:
+       * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
+       */
+      return (ctx->API == API_OPENGL_CORE && ctx->Version >= 31) ||
+         _mesa_has_OES_texture_buffer(ctx);
+   case GL_TEXTURE_CUBE_MAP_ARRAY:
+      return _mesa_has_texture_cube_map_array(ctx);
    }
 
    if (!_mesa_is_desktop_gl(ctx))
@@ -1237,8 +1278,7 @@ legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
       return GL_TRUE;
    case GL_PROXY_TEXTURE_CUBE_MAP:
       return ctx->Extensions.ARB_texture_cube_map;
-   case GL_TEXTURE_CUBE_MAP_ARRAY_ARB:
-   case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB:
+   case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
       return ctx->Extensions.ARB_texture_cube_map_array;
    case GL_TEXTURE_RECTANGLE_NV:
    case GL_PROXY_TEXTURE_RECTANGLE_NV:
@@ -1247,25 +1287,6 @@ legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
       return ctx->Extensions.EXT_texture_array;
-   case GL_TEXTURE_BUFFER:
-      /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
-       * but not in earlier versions that expose ARB_texture_buffer_object.
-       *
-       * From the ARB_texture_buffer_object spec:
-       * "(7) Do buffer textures support texture parameters (TexParameter) or
-       *      queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
-       *
-       *    RESOLVED:  No. [...] Note that the spec edits above don't add
-       *    explicit error language for any of these cases.  That is because
-       *    each of the functions enumerate the set of valid <target>
-       *    parameters.  Not editing the spec to allow TEXTURE_BUFFER_ARB in
-       *    these cases means that target is not legal, and an INVALID_ENUM
-       *    error should be generated."
-       *
-       * From the OpenGL 3.1 spec:
-       * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
-       */
-      return ctx->API == API_OPENGL_CORE && ctx->Version >= 31;
    case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
    case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
       return ctx->Extensions.ARB_texture_multisample;
@@ -1310,6 +1331,7 @@ get_tex_level_parameter_image(struct gl_context *ctx,
       dummy_image.TexFormat = MESA_FORMAT_NONE;
       dummy_image.InternalFormat = GL_RGBA;
       dummy_image._BaseFormat = GL_NONE;
+      dummy_image.FixedSampleLocations = GL_TRUE;
 
       img = &dummy_image;
    }
@@ -1399,16 +1421,15 @@ get_tex_level_parameter_image(struct gl_context *ctx,
 
       /* GL_ARB_texture_compression */
       case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
-        if (_mesa_is_format_compressed(texFormat) &&
+         if (_mesa_is_format_compressed(texFormat) &&
              !_mesa_is_proxy_texture(target)) {
             *params = _mesa_format_image_size(texFormat, img->Width,
                                               img->Height, img->Depth);
-    }
-    else {
-       _mesa_error(ctx, GL_INVALID_OPERATION,
-                   "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
-                   _mesa_enum_to_string(pname));
-    }
+         } else {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
+                        _mesa_enum_to_string(pname));
+         }
          break;
       case GL_TEXTURE_COMPRESSED:
          *params = (GLint) _mesa_is_format_compressed(texFormat);
@@ -1446,6 +1467,29 @@ get_tex_level_parameter_image(struct gl_context *ctx,
          *params = img->FixedSampleLocations;
          break;
 
+      /* There is never a buffer data store here, but these pnames still have
+       * to work.
+       */
+
+      /* GL_ARB_texture_buffer_object */
+      case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
+         if (!ctx->Extensions.ARB_texture_buffer_object)
+            goto invalid_pname;
+         *params = 0;
+         break;
+
+      /* GL_ARB_texture_buffer_range */
+      case GL_TEXTURE_BUFFER_OFFSET:
+         if (!ctx->Extensions.ARB_texture_buffer_range)
+            goto invalid_pname;
+         *params = 0;
+         break;
+      case GL_TEXTURE_BUFFER_SIZE:
+         if (!ctx->Extensions.ARB_texture_buffer_range)
+            goto invalid_pname;
+         *params = 0;
+         break;
+
       default:
          goto invalid_pname;
    }
@@ -1460,6 +1504,9 @@ invalid_pname:
 }
 
 
+/**
+ * Handle a glGetTexLevelParamteriv() call for a texture buffer.
+ */
 static void
 get_tex_level_parameter_buffer(struct gl_context *ctx,
                                const struct gl_texture_object *texObj,
@@ -1467,13 +1514,26 @@ get_tex_level_parameter_buffer(struct gl_context *ctx,
 {
    const struct gl_buffer_object *bo = texObj->BufferObject;
    mesa_format texFormat = texObj->_BufferObjectFormat;
+   int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
    GLenum internalFormat = texObj->BufferObjectFormat;
    GLenum baseFormat = _mesa_get_format_base_format(texFormat);
    const char *suffix = dsa ? "ture" : "";
 
+   assert(texObj->Target == GL_TEXTURE_BUFFER);
+
    if (!bo) {
       /* undefined texture buffer object */
-      *params = pname == GL_TEXTURE_COMPONENTS ? 1 : 0;
+      switch (pname) {
+      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
+         *params = GL_TRUE;
+         break;
+      case GL_TEXTURE_INTERNAL_FORMAT:
+         *params = internalFormat;
+         break;
+      default:
+         *params = 0;
+         break;
+      }
       return;
    }
 
@@ -1482,10 +1542,13 @@ get_tex_level_parameter_buffer(struct gl_context *ctx,
          *params = bo->Name;
          break;
       case GL_TEXTURE_WIDTH:
-         *params = bo->Size;
+         *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
+            / bytes;
          break;
       case GL_TEXTURE_HEIGHT:
       case GL_TEXTURE_DEPTH:
+         *params = 1;
+         break;
       case GL_TEXTURE_BORDER:
       case GL_TEXTURE_SHARED_SIZE:
       case GL_TEXTURE_COMPRESSED:
@@ -1535,6 +1598,19 @@ get_tex_level_parameter_buffer(struct gl_context *ctx,
          *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
          break;
 
+      /* GL_ARB_texture_multisample */
+      case GL_TEXTURE_SAMPLES:
+         if (!ctx->Extensions.ARB_texture_multisample)
+            goto invalid_pname;
+         *params = 0;
+         break;
+
+      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
+         if (!ctx->Extensions.ARB_texture_multisample)
+            goto invalid_pname;
+         *params = GL_TRUE;
+         break;
+
       /* GL_ARB_texture_compression */
       case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
          /* Always illegal for GL_TEXTURE_BUFFER */
@@ -1577,7 +1653,7 @@ valid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
                                    bool dsa)
 {
    const char *suffix = dsa ? "ture" : "";
-   if (!legal_get_tex_level_parameter_target(ctx, target, dsa)) {
+   if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
       _mesa_error(ctx, GL_INVALID_ENUM,
                   "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
                   _mesa_enum_to_string(target));
@@ -1734,7 +1810,8 @@ get_tex_parameterfv(struct gl_context *ctx,
          *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
          break;
       case GL_TEXTURE_BORDER_COLOR:
-         if (!_mesa_is_desktop_gl(ctx))
+         if (ctx->API == API_OPENGLES ||
+             !ctx->Extensions.ARB_texture_border_clamp)
             goto invalid_pname;
 
          if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
@@ -1968,7 +2045,8 @@ get_tex_parameteriv(struct gl_context *ctx,
          *params = (GLint) obj->Sampler.WrapR;
          break;
       case GL_TEXTURE_BORDER_COLOR:
-         if (!_mesa_is_desktop_gl(ctx))
+         if (ctx->API == API_OPENGLES ||
+             !ctx->Extensions.ARB_texture_border_clamp)
             goto invalid_pname;
 
          {
@@ -2275,13 +2353,9 @@ _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
    struct gl_texture_object *obj;
    GET_CURRENT_CONTEXT(ctx);
 
-   obj = get_texobj_by_name(ctx, texture, GL_TRUE);
-   if (!obj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameterfv(texture)");
+   obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
+   if (!obj)
       return;
-   }
 
    get_tex_parameterfv(ctx, obj, pname, params, true);
 }
@@ -2292,13 +2366,9 @@ _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
    struct gl_texture_object *obj;
    GET_CURRENT_CONTEXT(ctx);
 
-   obj = get_texobj_by_name(ctx, texture, GL_TRUE);
-   if (!obj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameteriv(texture)");
+   obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
+   if (!obj)
       return;
-   }
 
    get_tex_parameteriv(ctx, obj, pname, params, true);
 }
@@ -2309,13 +2379,9 @@ _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameterIiv(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
+   if (!texObj)
       return;
-   }
 
    get_tex_parameterIiv(ctx, texObj, pname, params, true);
 }
@@ -2327,13 +2393,9 @@ _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameterIuiv(texture)");
+   texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
+   if (!texObj)
       return;
-   }
 
    get_tex_parameterIuiv(ctx, texObj, pname, params, true);
 }