mesa: fix potential mem leak in generate_mipmap_compressed()
[mesa.git] / src / mesa / main / samplerobj.c
index 55acb6d1f5c5c28c32fece243c26ebfff2b9e501..7cf0654ada28a681154038e5163c972ae1550e1b 100644 (file)
@@ -63,7 +63,7 @@ _mesa_reference_sampler_object(struct gl_context *ctx,
       return;
 
    if (*ptr) {
-      /* Unreference the old buffer */
+      /* Unreference the old sampler */
       GLboolean deleteFlag = GL_FALSE;
       struct gl_sampler_object *oldSamp = *ptr;
 
@@ -90,9 +90,9 @@ _mesa_reference_sampler_object(struct gl_context *ctx,
       /* reference new sampler */
       /*_glthread_LOCK_MUTEX(samp->Mutex);*/
       if (samp->RefCount == 0) {
-         /* this buffer's being deleted (look just above) */
+         /* this sampler's being deleted (look just above) */
          /* Not sure this can every really happen.  Warn if it does. */
-         _mesa_problem(NULL, "referencing deleted buffer object");
+         _mesa_problem(NULL, "referencing deleted sampler object");
          *ptr = NULL;
       }
       else {
@@ -132,7 +132,8 @@ _mesa_init_sampler_object(struct gl_sampler_object *sampObj, GLuint name)
    sampObj->CompareMode = GL_NONE;
    sampObj->CompareFunc = GL_LEQUAL;
    sampObj->CompareFailValue = 0.0;
-   sampObj->sRGBDecode = GL_FALSE;
+   sampObj->sRGBDecode = GL_DECODE_EXT;
+   sampObj->CubeMapSeamless = GL_FALSE;
    sampObj->DepthMode = 0;
 }
 
@@ -250,7 +251,7 @@ _mesa_BindSampler(GLuint unit, GLuint sampler)
    struct gl_sampler_object *sampObj;
    GET_CURRENT_CONTEXT(ctx);
 
-   if (unit >= ctx->Const.MaxTextureImageUnits) {
+   if (unit >= ctx->Const.MaxCombinedTextureImageUnits) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glBindSampler(unit %u)", unit);
       return;
    }
@@ -281,7 +282,7 @@ _mesa_BindSampler(GLuint unit, GLuint sampler)
 
 
 /**
- * Check if a coordinate wrap mode is supported for the texture target.
+ * Check if a coordinate wrap mode is legal.
  * \return GL_TRUE if legal, GL_FALSE otherwise
  */
 static GLboolean 
@@ -293,11 +294,10 @@ validate_texture_wrap_mode(struct gl_context *ctx, GLenum wrap)
    case GL_CLAMP:
    case GL_CLAMP_TO_EDGE:
    case GL_REPEAT:
+   case GL_MIRRORED_REPEAT:
       return GL_TRUE;
    case GL_CLAMP_TO_BORDER:
       return e->ARB_texture_border_clamp;
-   case GL_MIRRORED_REPEAT:
-      return e->ARB_texture_mirrored_repeat;
    case GL_MIRROR_CLAMP_EXT:
       return e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp;
    case GL_MIRROR_CLAMP_TO_EDGE_EXT:
@@ -313,7 +313,7 @@ validate_texture_wrap_mode(struct gl_context *ctx, GLenum wrap)
 /**
  * This is called just prior to changing any sampler object state.
  */
-static INLINE void
+static inline void
 flush(struct gl_context *ctx)
 {
    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
@@ -481,7 +481,7 @@ set_sampler_min_lod(struct gl_context *ctx, struct gl_sampler_object *samp,
 
 static GLuint
 set_sampler_max_lod(struct gl_context *ctx, struct gl_sampler_object *samp,
-                    GLint param)
+                    GLfloat param)
 {
    if (samp->MaxLod == param)
       return GL_FALSE;
@@ -567,6 +567,25 @@ set_sampler_max_anisotropy(struct gl_context *ctx,
 }
 
 
+static GLuint
+set_sampler_cube_map_seamless(struct gl_context *ctx,
+                              struct gl_sampler_object *samp, GLboolean param)
+{
+   if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
+      return INVALID_PNAME;
+
+   if (samp->CubeMapSeamless == param)
+      return GL_FALSE;
+
+   if (param != GL_TRUE && param != GL_FALSE)
+      return INVALID_VALUE;
+
+   flush(ctx);
+   samp->CubeMapSeamless = param;
+   return GL_TRUE;
+}
+
+
 static void GLAPIENTRY
 _mesa_SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
 {
@@ -615,6 +634,9 @@ _mesa_SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) param);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      res = set_sampler_cube_map_seamless(ctx, sampObj, param);
+      break;
    case GL_TEXTURE_BORDER_COLOR:
       /* fall-through */
    default:
@@ -696,6 +718,9 @@ _mesa_SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       res = set_sampler_max_anisotropy(ctx, sampObj, param);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      res = set_sampler_cube_map_seamless(ctx, sampObj, (GLboolean) param);
+      break;
    case GL_TEXTURE_BORDER_COLOR:
       /* fall-through */
    default:
@@ -774,6 +799,9 @@ _mesa_SamplerParameteriv(GLuint sampler, GLenum pname, const GLint *params)
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) params[0]);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      res = set_sampler_cube_map_seamless(ctx, sampObj, params[0]);
+      break;
    case GL_TEXTURE_BORDER_COLOR:
       {
          GLfloat c[4];
@@ -862,6 +890,9 @@ _mesa_SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *params)
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       res = set_sampler_max_anisotropy(ctx, sampObj, params[0]);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      res = set_sampler_cube_map_seamless(ctx, sampObj, (GLboolean) params[0]);
+      break;
    case GL_TEXTURE_BORDER_COLOR:
       res = set_sampler_border_colorf(ctx, sampObj, params);
       break;
@@ -941,6 +972,9 @@ _mesa_SamplerParameterIiv(GLuint sampler, GLenum pname, const GLint *params)
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) params[0]);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      res = set_sampler_cube_map_seamless(ctx, sampObj, params[0]);
+      break;
    case GL_TEXTURE_BORDER_COLOR:
       res = set_sampler_border_colori(ctx, sampObj, params);
       break;
@@ -1021,6 +1055,9 @@ _mesa_SamplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *params)
    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
       res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) params[0]);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      res = set_sampler_cube_map_seamless(ctx, sampObj, params[0]);
+      break;
    case GL_TEXTURE_BORDER_COLOR:
       res = set_sampler_border_colorui(ctx, sampObj, params);
       break;
@@ -1110,6 +1147,11 @@ _mesa_GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
       params[2] = FLOAT_TO_INT(sampObj->BorderColor.f[2]);
       params[3] = FLOAT_TO_INT(sampObj->BorderColor.f[3]);
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
+         goto invalid_pname;
+      *params = sampObj->CubeMapSeamless;
+      break;
    default:
       goto invalid_pname;
    }
@@ -1178,6 +1220,11 @@ _mesa_GetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
       params[2] = sampObj->BorderColor.f[2];
       params[3] = sampObj->BorderColor.f[3];
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
+         goto invalid_pname;
+      *params = (GLfloat) sampObj->CubeMapSeamless;
+      break;
    default:
       goto invalid_pname;
    }
@@ -1247,6 +1294,11 @@ _mesa_GetSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
       params[2] = sampObj->BorderColor.i[2];
       params[3] = sampObj->BorderColor.i[3];
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
+         goto invalid_pname;
+      *params = sampObj->CubeMapSeamless;
+      break;
    default:
       goto invalid_pname;
    }
@@ -1316,6 +1368,11 @@ _mesa_GetSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
       params[2] = sampObj->BorderColor.ui[2];
       params[3] = sampObj->BorderColor.ui[3];
       break;
+   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
+      if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
+         goto invalid_pname;
+      *params = sampObj->CubeMapSeamless;
+      break;
    default:
       goto invalid_pname;
    }