mesa: Allow GL_TEXTURE_CUBE_MAP target with compressed internal formats
[mesa.git] / src / mesa / main / texstorage.c
index 1dd63a3173745d9a317c3f44bc7a2f40ddf80abe..897d5891a87b8bc94ea4230d87c1c0d3411a68ed 100644 (file)
@@ -39,7 +39,9 @@
 #include "texobj.h"
 #include "mipmap.h"
 #include "texstorage.h"
+#include "textureview.h"
 #include "mtypes.h"
+#include "glformats.h"
 
 
 
 static GLboolean
 legal_texobj_target(struct gl_context *ctx, GLuint dims, GLenum target)
 {
+   if (_mesa_is_gles3(ctx)
+       && target != GL_TEXTURE_2D
+       && target != GL_TEXTURE_CUBE_MAP
+       && target != GL_TEXTURE_3D
+       && target != GL_TEXTURE_2D_ARRAY)
+      return GL_FALSE;
+
    switch (dims) {
    case 1:
       switch (target) {
@@ -119,7 +128,7 @@ initialize_texture_fields(struct gl_context *ctx,
                           struct gl_texture_object *texObj,
                           GLint levels,
                           GLsizei width, GLsizei height, GLsizei depth,
-                          GLenum internalFormat, gl_format texFormat)
+                          GLenum internalFormat, mesa_format texFormat)
 {
    const GLenum target = texObj->Target;
    const GLuint numFaces = _mesa_num_tex_faces(target);
@@ -150,9 +159,8 @@ initialize_texture_fields(struct gl_context *ctx,
 
 
 /**
- * Clear all fields of texture object to zeros.  Used for proxy texture tests.
- * Used for proxy texture tests (and to clean up when a texture memory
- * allocation fails).
+ * Clear all fields of texture object to zeros.  Used for proxy texture tests
+ * and to clean up when a texture memory allocation fails.
  */
 static void
 clear_texture_fields(struct gl_context *ctx,
@@ -243,6 +251,10 @@ _mesa_alloc_texture_storage(struct gl_context *ctx,
    int face;
    int level;
 
+   (void) width;
+   (void) height;
+   (void) depth;
+
    for (face = 0; face < numFaces; face++) {
       for (level = 0; level < levels; level++) {
          struct gl_texture_image *const texImage = texObj->Image[face][level];
@@ -290,6 +302,23 @@ tex_storage_error_check(struct gl_context *ctx, GLuint dims, GLenum target,
       return GL_TRUE;
    }
 
+   /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
+    *
+    *    "The ETC2/EAC texture compression algorithm supports only
+    *     two-dimensional images. If internalformat is an ETC2/EAC format,
+    *     CompressedTexImage3D will generate an INVALID_OPERATION error if
+    *     target is not TEXTURE_2D_ARRAY."
+    *
+    * This should also be applicable for glTexStorage3D().
+    */
+   if (_mesa_is_compressed_format(ctx, internalformat)
+       && !_mesa_target_can_be_compressed(ctx, target, internalformat)) {
+      _mesa_error(ctx, _mesa_is_desktop_gl(ctx)?
+                  GL_INVALID_ENUM : GL_INVALID_OPERATION,
+                  "glTexStorage3D(internalformat = %s)",
+                  _mesa_lookup_enum_by_nr(internalformat));
+   }
+
    /* levels check */
    if (levels < 1) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glTexStorage%uD(levels < 1)",
@@ -327,6 +356,11 @@ tex_storage_error_check(struct gl_context *ctx, GLuint dims, GLenum target,
       return GL_TRUE;
    }
 
+   /* additional checks for depth textures */
+   if (!_mesa_legal_texture_base_format_for_target(ctx, target, internalformat,
+                                                   dims, "glTexStorage"))
+      return GL_TRUE;
+
    return GL_FALSE;
 }
 
@@ -340,7 +374,7 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
 {
    struct gl_texture_object *texObj;
    GLboolean sizeOK, dimensionsOK;
-   gl_format texFormat;
+   mesa_format texFormat;
 
    GET_CURRENT_CONTEXT(ctx);
 
@@ -415,8 +449,8 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
          return;
       }
 
-      texObj->Immutable = GL_TRUE;
-      texObj->ImmutableLevels = levels;
+      _mesa_set_texture_view_state(ctx, texObj, target, levels);
+
    }
 }
 
@@ -459,7 +493,16 @@ _mesa_TextureStorage1DEXT(GLuint texture, GLenum target, GLsizei levels,
                           GLenum internalformat,
                           GLsizei width)
 {
-   /* no-op */
+   GET_CURRENT_CONTEXT(ctx);
+
+   (void) texture;
+   (void) target;
+   (void) levels;
+   (void) internalformat;
+   (void) width;
+
+   _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glTextureStorage1DEXT not supported");
 }
 
 
@@ -468,7 +511,17 @@ _mesa_TextureStorage2DEXT(GLuint texture, GLenum target, GLsizei levels,
                           GLenum internalformat,
                           GLsizei width, GLsizei height)
 {
-   /* no-op */
+   GET_CURRENT_CONTEXT(ctx);
+
+   (void) texture;
+   (void) target;
+   (void) levels;
+   (void) internalformat;
+   (void) width;
+   (void) height;
+
+   _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glTextureStorage2DEXT not supported");
 }
 
 
@@ -478,5 +531,16 @@ _mesa_TextureStorage3DEXT(GLuint texture, GLenum target, GLsizei levels,
                           GLenum internalformat,
                           GLsizei width, GLsizei height, GLsizei depth)
 {
-   /* no-op */
+   GET_CURRENT_CONTEXT(ctx);
+
+   (void) texture;
+   (void) target;
+   (void) levels;
+   (void) internalformat;
+   (void) width;
+   (void) height;
+   (void) depth;
+
+   _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glTextureStorage3DEXT not supported");
 }