[Mesa-dev] [RFC 49/63] mesa/formatquery: Added compressed texture related queries

Eduardo Lima Mitev elima at igalia.com
Tue Jan 19 08:42:29 PST 2016


From: Antia Puentes <apuentes at igalia.com>

>From the ARB_internalformat_query2 specification:

   "- TEXTURE_COMPRESSED: If <internalformat> is a compressed format
      that is supported for this type of resource, TRUE is returned in
      <params>. If the internal format is not compressed, or the type of
      resource is not supported, FALSE is returned.

    - TEXTURE_COMPRESSED_BLOCK_WIDTH: If the resource contains a compressed
      format, the width of a compressed block (in bytes) is returned in
      <params>. If the internal format is not compressed, or the resource
      is not supported, 0 is returned.

    - TEXTURE_COMPRESSED_BLOCK_HEIGHT: If the resource contains a compressed
      format, the height of a compressed block (in bytes) is returned in
      <params>. If the internal format is not compressed, or the resource
      is not supported, 0 is returned.

    - TEXTURE_COMPRESSED_BLOCK_SIZE: If the resource contains a compressed
      format the number of bytes per block is returned in <params>.  If the
      internal format is not compressed, or the resource is not supported,
      0 is returned.
      (combined with the above, allows the bitrate to be computed, and may be
      useful in conjunction with ARB_compressed_texture_pixel_storage)."
---
 src/mesa/main/formatquery.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/mesa/main/formatquery.c b/src/mesa/main/formatquery.c
index 84f5529..e19309c 100644
--- a/src/mesa/main/formatquery.c
+++ b/src/mesa/main/formatquery.c
@@ -34,6 +34,7 @@
 #include "get.h"
 #include "genmipmap.h"
 #include "shaderimage.h"
+#include "texcompress.h"
 
 static bool
 _is_renderable(struct gl_context *ctx, GLenum internalformat)
@@ -1292,20 +1293,38 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
       break;
 
    case GL_TEXTURE_COMPRESSED:
-      /* @TODO */
+      buffer[0] = _mesa_is_compressed_format(ctx, internalformat);
       break;
 
    case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
-      /* @TODO */
-      break;
-
    case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
-      /* @TODO */
-      break;
+   case GL_TEXTURE_COMPRESSED_BLOCK_SIZE: {
+      mesa_format mesaformat;
+      GLint block_size;
 
-   case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
-      /* @TODO */
+      mesaformat = _mesa_glenum_to_compressed_format(internalformat);
+      if (mesaformat == MESA_FORMAT_NONE)
+         goto end;
+
+      block_size = _mesa_get_format_bytes(mesaformat);
+      assert(block_size > 0);
+
+      if (pname == GL_TEXTURE_COMPRESSED_BLOCK_SIZE) {
+         buffer[0] = block_size;
+      } else {
+         GLuint bwidth, bheight;
+
+         /* Returns the width and height in pixels. We return bytes */
+         _mesa_get_format_block_size(mesaformat, &bwidth, &bheight);
+         assert(bwidth > 0 && bheight > 0);
+
+         if (pname == GL_TEXTURE_COMPRESSED_BLOCK_WIDTH)
+            buffer[0] = block_size / bheight;
+         else
+            buffer[0] = block_size / bwidth;
+      }
       break;
+   }
 
    case GL_CLEAR_BUFFER:
       /* @TODO */
-- 
2.5.3



More information about the mesa-dev mailing list