mesa: Allow GL_TEXTURE_CUBE_MAP target with compressed internal formats
[mesa.git] / src / mesa / main / texstorage.c
index 86c8f3c922dbea4977fc7a3a242f8eebca499c6e..897d5891a87b8bc94ea4230d87c1c0d3411a68ed 100644 (file)
@@ -41,6 +41,7 @@
 #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) {
@@ -294,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)",