mesa: minor whitespace fixes, line wrapping in texcompress.c
[mesa.git] / src / mesa / main / texparam.c
index 5cdcb79ec302ad13dc89861713a661df8a7aec9b..4a0f61eda8182b67105b963bf009183c298b2bb7 100644 (file)
@@ -157,14 +157,9 @@ 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,7 +174,7 @@ get_texobj_by_name(struct gl_context *ctx, GLuint texture, const char *name)
    case GL_TEXTURE_RECTANGLE:
       return texObj;
    default:
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", name);
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(target)", name);
       return NULL;
    }
 
@@ -276,6 +271,19 @@ 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 (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
@@ -368,8 +376,26 @@ set_tex_parameteri(struct gl_context *ctx,
       if (texObj->BaseLevel == params[0])
          return GL_FALSE;
 
+      /* Section 8.10 (Texture Parameters) of the OpenGL 4.5 Core Profile spec
+       * says:
+       *
+       *    An INVALID_OPERATION error is generated if the effective target is
+       *    TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY, or
+       *    TEXTURE_RECTANGLE, and pname TEXTURE_BASE_LEVEL is set to a value
+       *    other than zero.
+       *
+       * Note that section 3.8.8 (Texture Parameters) of the OpenGL 3.3 Core
+       * Profile spec said:
+       *
+       *    The error INVALID_VALUE is generated if TEXTURE_BASE_LEVEL is set
+       *    to any value other than zero.
+       *
+       * We take the 4.5 language as a correction to 3.3, and we implement
+       * that on all GL versions.
+       */
       if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
-           texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) && params[0] != 0)
+           texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY ||
+           texObj->Target == GL_TEXTURE_RECTANGLE) && params[0] != 0)
          goto invalid_operation;
 
       if (params[0] < 0) {
@@ -377,12 +403,6 @@ set_tex_parameteri(struct gl_context *ctx,
                      "glTex%sParameter(param=%d)", suffix, params[0]);
          return GL_FALSE;
       }
-      if (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glTex%sParameter(target=%s, param=%d)", suffix,
-                     _mesa_enum_to_string(texObj->Target), params[0]);
-         return GL_FALSE;
-      }
       incomplete(ctx, texObj);
 
       /** See note about ARB_texture_storage below */
@@ -602,6 +622,14 @@ set_tex_parameteri(struct gl_context *ctx,
       }
       goto invalid_pname;
 
+   case GL_TEXTURE_TILING_EXT:
+      if (ctx->Extensions.EXT_memory_object) {
+         texObj->TextureTiling = params[0];
+
+         return GL_TRUE;
+      }
+      goto invalid_pname;
+
    default:
       goto invalid_pname;
    }
@@ -639,6 +667,19 @@ 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))
@@ -715,8 +756,16 @@ set_tex_parameterf(struct gl_context *ctx,
       break;
 
    case GL_TEXTURE_BORDER_COLOR:
+      /* 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->Extensions.ARB_texture_border_clamp)
+          (ctx->API == API_OPENGLES2 &&
+           !ctx->Extensions.ARB_texture_border_clamp))
          goto invalid_pname;
 
       if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
@@ -737,6 +786,13 @@ set_tex_parameterf(struct gl_context *ctx,
       }
       return GL_TRUE;
 
+   case GL_TEXTURE_TILING_EXT:
+      if (ctx->Extensions.EXT_memory_object) {
+         texObj->TextureTiling = params[0];
+         return GL_TRUE;
+      }
+      goto invalid_pname;
+
    default:
       goto invalid_pname;
    }
@@ -933,10 +989,6 @@ _mesa_texture_parameteriv(struct gl_context *ctx,
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
       {
-         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameteriv(texture)");
-            return;
-         }
          /* convert int params to float */
          GLfloat fparams[4];
          fparams[0] = INT_TO_FLOAT(params[0]);
@@ -977,6 +1029,12 @@ _mesa_texture_parameterIiv(struct gl_context *ctx,
 {
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
+      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;
@@ -999,6 +1057,12 @@ _mesa_texture_parameterIuiv(struct gl_context *ctx,
 {
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
+      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;
@@ -1111,11 +1175,8 @@ _mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glTextureParameterfv");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfv(texture)");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
 }
@@ -1127,11 +1188,8 @@ _mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glTextureParameterf");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterf(texture)");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterf(ctx, texObj, pname, param, true);
 }
@@ -1143,11 +1201,8 @@ _mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glTextureParameteri");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteri(texture)");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameteri(ctx, texObj, pname, param, true);
 }
@@ -1160,11 +1215,8 @@ _mesa_TextureParameteriv(GLuint texture, GLenum pname,
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glTextureParameteriv");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriv(texture)");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
 }
@@ -1177,12 +1229,8 @@ _mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIiv");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glTextureParameterIiv(texture)");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
 }
@@ -1194,12 +1242,8 @@ _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glTextureParameterIuiv(texture)");
+   if (!texObj)
       return;
-   }
 
    _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
 }
@@ -1243,8 +1287,8 @@ _mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target
        * 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);
+      return (_mesa_is_desktop_gl(ctx) && ctx->Version >= 31) ||
+             _mesa_has_OES_texture_buffer(ctx);
    case GL_TEXTURE_CUBE_MAP_ARRAY:
       return _mesa_has_texture_cube_map_array(ctx);
    }
@@ -1990,6 +2034,12 @@ get_tex_parameterfv(struct gl_context *ctx,
          *params = ENUM_TO_FLOAT(obj->Target);
          break;
 
+      case GL_TEXTURE_TILING_EXT:
+         if (!ctx->Extensions.EXT_memory_object)
+            goto invalid_pname;
+         *params = ENUM_TO_FLOAT(obj->TextureTiling);
+         break;
+
       default:
          goto invalid_pname;
    }
@@ -2222,6 +2272,12 @@ get_tex_parameteriv(struct gl_context *ctx,
          *params = (GLint) obj->Target;
          break;
 
+      case GL_TEXTURE_TILING_EXT:
+         if (!ctx->Extensions.EXT_memory_object)
+            goto invalid_pname;
+         *params = (GLint) obj->TextureTiling;
+         break;
+
       default:
          goto invalid_pname;
    }
@@ -2337,12 +2393,8 @@ _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
    GET_CURRENT_CONTEXT(ctx);
 
    obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
-   if (!obj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameterfv(texture)");
+   if (!obj)
       return;
-   }
 
    get_tex_parameterfv(ctx, obj, pname, params, true);
 }
@@ -2354,12 +2406,8 @@ _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
    GET_CURRENT_CONTEXT(ctx);
 
    obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
-   if (!obj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameteriv(texture)");
+   if (!obj)
       return;
-   }
 
    get_tex_parameteriv(ctx, obj, pname, params, true);
 }
@@ -2371,12 +2419,8 @@ _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameterIiv(texture)");
+   if (!texObj)
       return;
-   }
 
    get_tex_parameterIiv(ctx, texObj, pname, params, true);
 }
@@ -2389,12 +2433,8 @@ _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
    GET_CURRENT_CONTEXT(ctx);
 
    texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
-   if (!texObj) {
-      /* User passed a non-generated name. */
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetTextureParameterIuiv(texture)");
+   if (!texObj)
       return;
-   }
 
    get_tex_parameterIuiv(ctx, texObj, pname, params, true);
 }