mesa: GL_EXT_packed_depth_stencil is not optional
[mesa.git] / src / mesa / main / texparam.c
index 32109951cb5f2b9f0d83f57767a61272c06e5e30..c02408c624b89ad70f46269eb15b6a79681173a1 100644 (file)
@@ -23,7 +23,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/** 
+/**
  * \file texparam.c
  *
  * glTexParameter-related functions
@@ -52,7 +52,7 @@
  * Check if a coordinate wrap mode is supported for the texture target.
  * \return GL_TRUE if legal, GL_FALSE otherwise
  */
-static GLboolean 
+static GLboolean
 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
 {
    const struct gl_extensions * const e = & ctx->Extensions;
@@ -84,16 +84,22 @@ validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
       break;
 
    case GL_MIRROR_CLAMP_EXT:
-   case GL_MIRROR_CLAMP_TO_EDGE_EXT:
-      supported = is_desktop_gl 
+      supported = is_desktop_gl
          && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
-        && (target != GL_TEXTURE_RECTANGLE_NV)
+         && (target != GL_TEXTURE_RECTANGLE_NV)
+         && (target != GL_TEXTURE_EXTERNAL_OES);
+      break;
+
+   case GL_MIRROR_CLAMP_TO_EDGE_EXT:
+      supported = is_desktop_gl
+         && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp || e->ARB_texture_mirror_clamp_to_edge)
+         && (target != GL_TEXTURE_RECTANGLE_NV)
          && (target != GL_TEXTURE_EXTERNAL_OES);
       break;
 
    case GL_MIRROR_CLAMP_TO_BORDER_EXT:
       supported = is_desktop_gl && e->EXT_texture_mirror_clamp
-        && (target != GL_TEXTURE_RECTANGLE_NV)
+         && (target != GL_TEXTURE_RECTANGLE_NV)
          && (target != GL_TEXTURE_EXTERNAL_OES);
       break;
 
@@ -152,16 +158,13 @@ get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
       }
       break;
    case GL_TEXTURE_1D_ARRAY_EXT:
-      if (_mesa_is_desktop_gl(ctx)
-          && (ctx->Extensions.MESA_texture_array ||
-              ctx->Extensions.EXT_texture_array)) {
+      if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array) {
          return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
       }
       break;
    case GL_TEXTURE_2D_ARRAY_EXT:
       if ((_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx))
-          && (ctx->Extensions.MESA_texture_array ||
-              ctx->Extensions.EXT_texture_array)) {
+          && ctx->Extensions.EXT_texture_array) {
          return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
       }
       break;
@@ -256,7 +259,7 @@ static inline void
 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-   _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
+   _mesa_dirty_texobj(ctx, texObj);
 }
 
 
@@ -386,7 +389,13 @@ set_tex_parameteri(struct gl_context *ctx,
          return GL_FALSE;
       }
       incomplete(ctx, texObj);
-      texObj->BaseLevel = params[0];
+
+      /** See note about ARB_texture_storage below */
+      if (texObj->Immutable)
+         texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]);
+      else
+         texObj->BaseLevel = params[0];
+
       return GL_TRUE;
 
    case GL_TEXTURE_MAX_LEVEL:
@@ -399,7 +408,19 @@ set_tex_parameteri(struct gl_context *ctx,
          return GL_FALSE;
       }
       incomplete(ctx, texObj);
-      texObj->MaxLevel = params[0];
+
+      /** From ARB_texture_storage:
+       * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
+       * clamped to the range [0, <levels> - 1] and level_max is then clamped to
+       * the range [level_base, <levels> - 1], where <levels> is the parameter
+       * passed the call to TexStorage* for the texture object.
+       */
+      if (texObj->Immutable)
+          texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel,
+                                   texObj->ImmutableLevels - 1);
+      else
+         texObj->MaxLevel = params[0];
+
       return GL_TRUE;
 
    case GL_GENERATE_MIPMAP_SGIS:
@@ -660,11 +681,8 @@ set_tex_parameterf(struct gl_context *ctx,
       return GL_FALSE;
 
    case GL_TEXTURE_LOD_BIAS:
-      /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
-       * It was removed in core-profile, and it has never existed in OpenGL
-       * ES.
-       */
-      if (ctx->API != API_OPENGL_COMPAT)
+      /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
+      if (_mesa_is_gles(ctx))
          goto invalid_pname;
 
       if (!target_allows_setting_sampler_parameters(texObj->Target))
@@ -1025,8 +1043,7 @@ legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target)
    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
    case GL_TEXTURE_2D_ARRAY_EXT:
    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
-      return (ctx->Extensions.MESA_texture_array ||
-              ctx->Extensions.EXT_texture_array);
+      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.
@@ -1146,9 +1163,6 @@ get_tex_level_parameter_image(struct gl_context *ctx,
          *params = _mesa_get_format_bits(texFormat, pname);
          break;
       case GL_TEXTURE_STENCIL_SIZE_EXT:
-         if (!ctx->Extensions.EXT_packed_depth_stencil &&
-             !ctx->Extensions.ARB_framebuffer_object)
-            goto invalid_pname;
          *params = _mesa_get_format_bits(texFormat, pname);
          break;
       case GL_TEXTURE_SHARED_SIZE:
@@ -1489,7 +1503,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
          *params = (GLfloat) obj->DepthMode;
          break;
       case GL_TEXTURE_LOD_BIAS:
-         if (ctx->API != API_OPENGL_COMPAT)
+         if (_mesa_is_gles(ctx))
             goto invalid_pname;
 
          *params = obj->Sampler.LodBias;
@@ -1541,9 +1555,35 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
          break;
 
       case GL_TEXTURE_IMMUTABLE_LEVELS:
-         if (!_mesa_is_gles3(ctx))
+         if (_mesa_is_gles3(ctx) ||
+             (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
+            *params = (GLfloat) obj->ImmutableLevels;
+         else
+            goto invalid_pname;
+         break;
+
+      case GL_TEXTURE_VIEW_MIN_LEVEL:
+         if (!ctx->Extensions.ARB_texture_view)
             goto invalid_pname;
-         *params = (GLfloat) obj->ImmutableLevels;
+         *params = (GLfloat) obj->MinLevel;
+         break;
+
+      case GL_TEXTURE_VIEW_NUM_LEVELS:
+         if (!ctx->Extensions.ARB_texture_view)
+            goto invalid_pname;
+         *params = (GLfloat) obj->NumLevels;
+         break;
+
+      case GL_TEXTURE_VIEW_MIN_LAYER:
+         if (!ctx->Extensions.ARB_texture_view)
+            goto invalid_pname;
+         *params = (GLfloat) obj->MinLayer;
+         break;
+
+      case GL_TEXTURE_VIEW_NUM_LAYERS:
+         if (!ctx->Extensions.ARB_texture_view)
+            goto invalid_pname;
+         *params = (GLfloat) obj->NumLayers;
          break;
 
       case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
@@ -1677,10 +1717,13 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          *params = (GLint) obj->DepthMode;
          break;
       case GL_TEXTURE_LOD_BIAS:
-         if (ctx->API != API_OPENGL_COMPAT)
+         if (_mesa_is_gles(ctx))
             goto invalid_pname;
 
-         *params = (GLint) obj->Sampler.LodBias;
+         /* GL spec 'Data Conversions' section specifies that floating-point
+          * value in integer Get function is rounded to nearest integer
+          */
+         *params = IROUND(obj->Sampler.LodBias);
          break;
       case GL_TEXTURE_CROP_RECT_OES:
          if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
@@ -1722,9 +1765,35 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
          break;
 
       case GL_TEXTURE_IMMUTABLE_LEVELS:
-         if (!_mesa_is_gles3(ctx))
+         if (_mesa_is_gles3(ctx) ||
+             (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
+            *params = obj->ImmutableLevels;
+         else
+            goto invalid_pname;
+         break;
+
+      case GL_TEXTURE_VIEW_MIN_LEVEL:
+         if (!ctx->Extensions.ARB_texture_view)
+            goto invalid_pname;
+         *params = (GLint) obj->MinLevel;
+         break;
+
+      case GL_TEXTURE_VIEW_NUM_LEVELS:
+         if (!ctx->Extensions.ARB_texture_view)
+            goto invalid_pname;
+         *params = (GLint) obj->NumLevels;
+         break;
+
+      case GL_TEXTURE_VIEW_MIN_LAYER:
+         if (!ctx->Extensions.ARB_texture_view)
+            goto invalid_pname;
+         *params = (GLint) obj->MinLayer;
+         break;
+
+      case GL_TEXTURE_VIEW_NUM_LAYERS:
+         if (!ctx->Extensions.ARB_texture_view)
             goto invalid_pname;
-         *params = obj->ImmutableLevels;
+         *params = (GLint) obj->NumLayers;
          break;
 
       case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
@@ -1763,7 +1832,7 @@ _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
    texObj = get_texobj(ctx, target, GL_TRUE);
    if (!texObj)
       return;
-   
+
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
       COPY_4V(params, texObj->Sampler.BorderColor.i);
@@ -1784,7 +1853,7 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
    texObj = get_texobj(ctx, target, GL_TRUE);
    if (!texObj)
       return;
-   
+
    switch (pname) {
    case GL_TEXTURE_BORDER_COLOR:
       COPY_4V(params, texObj->Sampler.BorderColor.i);
@@ -1794,7 +1863,7 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
          GLint ip[4];
          _mesa_GetTexParameteriv(target, pname, ip);
          params[0] = ip[0];
-         if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT || 
+         if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
              pname == GL_TEXTURE_CROP_RECT_OES) {
             params[1] = ip[1];
             params[2] = ip[2];