mesa/formatquery: support for IMAGE_FORMAT_COMPATIBILITY_TYPE
authorAlejandro Piñeiro <apinheiro@igalia.com>
Sat, 19 Dec 2015 10:02:21 +0000 (11:02 +0100)
committerEduardo Lima Mitev <elima@igalia.com>
Thu, 3 Mar 2016 14:14:06 +0000 (15:14 +0100)
From arb_internalformat_query2 spec:

 "IMAGE_FORMAT_COMPATIBILITY_TYPE: The matching criteria use for the
  resource when used as an image textures is returned in
  <params>. This is equivalent to calling GetTexParameter with <value>
  set to IMAGE_FORMAT_COMPATIBILITY_TYPE."

Current implementation of GetTexParameter for this case returns a
field of a texture object, so the support of this pname was
implemented creating a temporal texture object and returning that
value.

It is worth to mention that right now that field is not reassigned
after initialization. So it is somehow hardcoded. An alternative
option would be return that value. That doesn't seems really scalable
though.

v2: use _mesa_has## instead of direct ctx->Extensions access (Nanley Chery)

Reviewed-by: Dave Airlie <airlied@redhat.com>
src/mesa/main/formatquery.c

index 14c69f629df365ef6d12ca3468a96dfa473bcc8f..d9df6db3fbdd1e2acb25a5fc1e72196097047cae 100644 (file)
@@ -30,6 +30,7 @@
 #include "formatquery.h"
 #include "teximage.h"
 #include "texparam.h"
+#include "texobj.h"
 
 static bool
 _is_renderable(struct gl_context *ctx, GLenum internalformat)
@@ -948,9 +949,26 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
       /* @TODO */
       break;
 
-   case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
-      /* @TODO */
+   case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE: {
+      if (!_mesa_has_ARB_shader_image_load_store(ctx))
+         goto end;
+
+      if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, true))
+         goto end;
+
+      /* From spec: "Equivalent to calling GetTexParameter with <value> set
+       * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
+       *
+       * GetTexParameter just returns
+       * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
+       * just with the purpose of getting the value.
+       */
+      struct gl_texture_object *tex_obj = _mesa_new_texture_object(ctx, 0, target);
+      buffer[0] = tex_obj->ImageFormatCompatibilityType;
+      _mesa_delete_texture_object(ctx, tex_obj);
+
       break;
+   }
 
    case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
       /* @TODO */