[Mesa-dev] [PATCH 1/5] mesa: Add skeleton implementation of glGetInternalformativ

Ian Romanick idr at freedesktop.org
Fri Jan 4 17:43:40 PST 2013


From: Ian Romanick <ian.d.romanick at intel.com>

This is for the GL_ARB_internalformat_query extension and GLES 3.0.

v2: Generate GL_INVALID_OPERATION if the extension is not supported.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 src/mesa/main/formatquery.c | 124 ++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/formatquery.h |  35 +++++++++++++
 src/mesa/sources.mak        |   1 +
 3 files changed, 160 insertions(+)
 create mode 100644 src/mesa/main/formatquery.c
 create mode 100644 src/mesa/main/formatquery.h

diff --git a/src/mesa/main/formatquery.c b/src/mesa/main/formatquery.c
new file mode 100644
index 0000000..64f10cd
--- /dev/null
+++ b/src/mesa/main/formatquery.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "mtypes.h"
+#include "glformats.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "enums.h"
+#include "fbobject.h"
+#include "formatquery.h"
+
+void GLAPIENTRY
+_mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
+                          GLsizei bufSize, GLint *params)
+{
+   GLint buffer[16];
+   GLsizei count = 0;
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!ctx->Extensions.ARB_internalformat_query) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformativ");
+      return;
+   }
+
+   /* The ARB_internalformat_query spec says:
+    *
+    *     "If the <target> parameter to GetInternalformativ is not one of
+    *     TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY or RENDERBUFFER
+    *     then an INVALID_ENUM error is generated."
+    */
+   switch (target) {
+   case GL_RENDERBUFFER:
+      break;
+
+   case GL_TEXTURE_2D_MULTISAMPLE:
+   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+      /* Mesa does not currently support GL_ARB_texture_multisample, so these
+       * enums are not valid on this implementation either.
+       */
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetInternalformativ(target=%s)",
+                  _mesa_lookup_enum_by_nr(target));
+      return;
+   }
+
+   /* The ARB_internalformat_query spec says:
+    *
+    *     "If the <internalformat> parameter to GetInternalformativ is not
+    *     color-, depth- or stencil-renderable, then an INVALID_ENUM error is
+    *     generated."
+    */
+   if (_mesa_base_fbo_format(ctx, internalformat) == 0) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetInternalformativ(internalformat=%s)",
+                  _mesa_lookup_enum_by_nr(internalformat));
+      return;
+   }
+
+   /* The ARB_internalformat_query spec says:
+    *
+    *     "If the <bufSize> parameter to GetInternalformativ is negative, then
+    *     an INVALID_VALUE error is generated."
+    */
+   if (bufSize < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                  "glGetInternalformativ(target=%s)",
+                  _mesa_lookup_enum_by_nr(target));
+      return;
+   }
+
+   switch (pname) {
+   case GL_SAMPLES:
+      buffer[0] = ctx->Const.MaxSamples;
+      count = 1;
+      break;
+   case GL_NUM_SAMPLE_COUNTS:
+      buffer[0] = 1;
+      count = 1;
+      break;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetInternalformativ(pname=%s)",
+                  _mesa_lookup_enum_by_nr(pname));
+      return;
+   }
+
+   if (bufSize != 0 && params == NULL) {
+      /* Emit a warning to aid application debugging, but go ahead and do the
+       * memcpy (and probably crash) anyway.
+       */
+      _mesa_warning(ctx,
+                    "glGetInternalformativ(bufSize = %d, but params = NULL)",
+                    bufSize);
+   }
+
+   /* Copy the data from the temporary buffer to the buffer supplied by the
+    * application.  Clamp the size of the copy to the size supplied by the
+    * application.
+    */
+   memcpy(params, buffer, MIN2(count, bufSize) * sizeof(GLint));
+
+   return;
+}
diff --git a/src/mesa/main/formatquery.h b/src/mesa/main/formatquery.h
new file mode 100644
index 0000000..585c3eb
--- /dev/null
+++ b/src/mesa/main/formatquery.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#ifndef FORMATQUERY_H
+#define FORMATQUERY_H
+
+#include "compiler.h"
+#include "glheader.h"
+
+extern void GLAPIENTRY
+_mesa_GetInternalformativ(GLenum target, GLenum internalformat,
+                          GLenum pname, GLsizei bufSize, GLint *params);
+
+#endif /* FORMATQUERY_H */
diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak
index 8cde2c4..178ceb2 100644
--- a/src/mesa/sources.mak
+++ b/src/mesa/sources.mak
@@ -42,6 +42,7 @@ MAIN_FILES = \
 	$(SRCDIR)main/ffvertex_prog.c \
 	$(SRCDIR)main/ff_fragment_shader.cpp \
 	$(SRCDIR)main/fog.c \
+	$(SRCDIR)main/formatquery.c \
 	$(SRCDIR)main/formats.c \
 	$(SRCDIR)main/format_pack.c \
 	$(SRCDIR)main/format_unpack.c \
-- 
1.7.11.7



More information about the mesa-dev mailing list