aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/querymatrix.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2015-03-22 13:30:59 +0100
committermarha <marha@users.sourceforge.net>2015-03-22 13:30:59 +0100
commit82c8df11062f72a7d467e26cedbbd8b322ff7a70 (patch)
tree7e7a3e408d09d3e50ff0d2f9befeb5b7ab5617a5 /mesalib/src/mesa/main/querymatrix.c
parent8574eba804031f6b19713f0b02952280730bf62e (diff)
downloadvcxsrv-82c8df11062f72a7d467e26cedbbd8b322ff7a70.tar.gz
vcxsrv-82c8df11062f72a7d467e26cedbbd8b322ff7a70.tar.bz2
vcxsrv-82c8df11062f72a7d467e26cedbbd8b322ff7a70.zip
randrproto fontconfig libX11 libXdmcp libxcb mesa xkbcomp xserver git update 22 Mar 2015
xserver commit 0a78b599b34cc8b5fe6fe82f90e90234e8ab7a56 libxcb commit a90be9955d2c5a635f791d44db1154633b9d3322 libX11 commit 5a499ca7b064bf7e6a4fcc169f22862dce0c60c5 libXdmcp commit 0c09444d276fbf46a0e8b427a4f6a325d0625742 xkbcomp commit fc3e6ddb2c8e922ea80f2dc5cbc1df2102e30d99 randrproto commit b1ba68df8a5fc113a387123ec2f312195e28e47f fontconfig commit 69ff6b6e260584e383c38b1b7034ddcbb23d214f mesa commit 397b491173f0d2df4deb44d21c170bf16840d507
Diffstat (limited to 'mesalib/src/mesa/main/querymatrix.c')
-rw-r--r--mesalib/src/mesa/main/querymatrix.c279
1 files changed, 115 insertions, 164 deletions
diff --git a/mesalib/src/mesa/main/querymatrix.c b/mesalib/src/mesa/main/querymatrix.c
index ef8517571..18361c929 100644
--- a/mesalib/src/mesa/main/querymatrix.c
+++ b/mesalib/src/mesa/main/querymatrix.c
@@ -13,7 +13,7 @@
#include <stdlib.h>
-#include <math.h>
+#include "c99_math.h"
#include "glheader.h"
#include "querymatrix.h"
#include "main/get.h"
@@ -37,169 +37,120 @@
#define INT_TO_FIXED(x) ((GLfixed) ((x) << 16))
#define FLOAT_TO_FIXED(x) ((GLfixed) ((x) * 65536.0))
-#if defined(fpclassify)
-/* ISO C99 says that fpclassify is a macro. Assume that any implementation
- * of fpclassify, whether it's in a C99 compiler or not, will be a macro.
- */
-#elif defined(_MSC_VER)
-/* Not required on VS2013 and above. */
-/* Oddly, the fpclassify() function doesn't exist in such a form
- * on MSVC. This is an implementation using slightly different
- * lower-level Windows functions.
- */
-#include <float.h>
-
-enum {FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_NORMAL}
-fpclassify(double x)
-{
- switch(_fpclass(x)) {
- case _FPCLASS_SNAN: /* signaling NaN */
- case _FPCLASS_QNAN: /* quiet NaN */
- return FP_NAN;
- case _FPCLASS_NINF: /* negative infinity */
- case _FPCLASS_PINF: /* positive infinity */
- return FP_INFINITE;
- case _FPCLASS_NN: /* negative normal */
- case _FPCLASS_PN: /* positive normal */
- return FP_NORMAL;
- case _FPCLASS_ND: /* negative denormalized */
- case _FPCLASS_PD: /* positive denormalized */
- return FP_SUBNORMAL;
- case _FPCLASS_NZ: /* negative zero */
- case _FPCLASS_PZ: /* positive zero */
- return FP_ZERO;
- default:
- /* Should never get here; but if we do, this will guarantee
- * that the pattern is not treated like a number.
- */
- return FP_NAN;
- }
-}
-
-#else
-
-enum {FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL, FP_NORMAL}
-fpclassify(double x)
-{
- /* XXX do something better someday */
- return FP_NORMAL;
-}
-
-#endif
-GLbitfield GLAPIENTRY _mesa_QueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16])
+GLbitfield GLAPIENTRY
+_mesa_QueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16])
{
- GLfloat matrix[16];
- GLint tmp;
- GLenum currentMode = GL_FALSE;
- GLenum desiredMatrix = GL_FALSE;
- /* The bitfield returns 1 for each component that is invalid (i.e.
- * NaN or Inf). In case of error, everything is invalid.
- */
- GLbitfield rv;
- register unsigned int i;
- unsigned int bit;
-
- /* This data structure defines the mapping between the current matrix
- * mode and the desired matrix identifier.
- */
- static struct {
- GLenum currentMode;
- GLenum desiredMatrix;
- } modes[] = {
- {GL_MODELVIEW, GL_MODELVIEW_MATRIX},
- {GL_PROJECTION, GL_PROJECTION_MATRIX},
- {GL_TEXTURE, GL_TEXTURE_MATRIX},
- };
-
- /* Call Mesa to get the current matrix in floating-point form. First,
- * we have to figure out what the current matrix mode is.
- */
- _mesa_GetIntegerv(GL_MATRIX_MODE, &tmp);
- currentMode = (GLenum) tmp;
-
- /* The mode is either GL_FALSE, if for some reason we failed to query
- * the mode, or a given mode from the above table. Search for the
- * returned mode to get the desired matrix; if we don't find it,
- * we can return immediately, as _mesa_GetInteger() will have
- * logged the necessary error already.
- */
- for (i = 0; i < sizeof(modes)/sizeof(modes[0]); i++) {
- if (modes[i].currentMode == currentMode) {
- desiredMatrix = modes[i].desiredMatrix;
- break;
- }
- }
- if (desiredMatrix == GL_FALSE) {
- /* Early error means all values are invalid. */
- return 0xffff;
- }
-
- /* Now pull the matrix itself. */
- _mesa_GetFloatv(desiredMatrix, matrix);
-
- rv = 0;
- for (i = 0, bit = 1; i < 16; i++, bit<<=1) {
- float normalizedFraction;
- int exp;
-
- switch (fpclassify(matrix[i])) {
- /* A "subnormal" or denormalized number is too small to be
- * represented in normal format; but despite that it's a
- * valid floating point number. FP_ZERO and FP_NORMAL
- * are both valid as well. We should be fine treating
- * these three cases as legitimate floating-point numbers.
- */
- case FP_SUBNORMAL:
- case FP_NORMAL:
- case FP_ZERO:
- normalizedFraction = (GLfloat)frexp(matrix[i], &exp);
- mantissa[i] = FLOAT_TO_FIXED(normalizedFraction);
- exponent[i] = (GLint) exp;
- break;
-
- /* If the entry is not-a-number or an infinity, then the
- * matrix component is invalid. The invalid flag for
- * the component is already set; might as well set the
- * other return values to known values. We'll set
- * distinct values so that a savvy end user could determine
- * whether the matrix component was a NaN or an infinity,
- * but this is more useful for debugging than anything else
- * since the standard doesn't specify any such magic
- * values to return.
- */
- case FP_NAN:
- mantissa[i] = INT_TO_FIXED(0);
- exponent[i] = (GLint) 0;
- rv |= bit;
- break;
-
- case FP_INFINITE:
- /* Return +/- 1 based on whether it's a positive or
- * negative infinity.
- */
- if (matrix[i] > 0) {
- mantissa[i] = INT_TO_FIXED(1);
- }
- else {
- mantissa[i] = -INT_TO_FIXED(1);
- }
- exponent[i] = (GLint) 0;
- rv |= bit;
- break;
-
- /* We should never get here; but here's a catching case
- * in case fpclassify() is returnings something unexpected.
- */
- default:
- mantissa[i] = INT_TO_FIXED(2);
- exponent[i] = (GLint) 0;
- rv |= bit;
- break;
- }
-
- } /* for each component */
-
- /* All done */
- return rv;
+ GLfloat matrix[16];
+ GLint tmp;
+ GLenum currentMode = GL_FALSE;
+ GLenum desiredMatrix = GL_FALSE;
+ /* The bitfield returns 1 for each component that is invalid (i.e.
+ * NaN or Inf). In case of error, everything is invalid.
+ */
+ GLbitfield rv;
+ unsigned i, bit;
+
+ /* This data structure defines the mapping between the current matrix
+ * mode and the desired matrix identifier.
+ */
+ static const struct {
+ GLenum currentMode;
+ GLenum desiredMatrix;
+ } modes[] = {
+ {GL_MODELVIEW, GL_MODELVIEW_MATRIX},
+ {GL_PROJECTION, GL_PROJECTION_MATRIX},
+ {GL_TEXTURE, GL_TEXTURE_MATRIX},
+ };
+
+ /* Call Mesa to get the current matrix in floating-point form. First,
+ * we have to figure out what the current matrix mode is.
+ */
+ _mesa_GetIntegerv(GL_MATRIX_MODE, &tmp);
+ currentMode = (GLenum) tmp;
+
+ /* The mode is either GL_FALSE, if for some reason we failed to query
+ * the mode, or a given mode from the above table. Search for the
+ * returned mode to get the desired matrix; if we don't find it,
+ * we can return immediately, as _mesa_GetInteger() will have
+ * logged the necessary error already.
+ */
+ for (i = 0; i < ARRAY_SIZE(modes); i++) {
+ if (modes[i].currentMode == currentMode) {
+ desiredMatrix = modes[i].desiredMatrix;
+ break;
+ }
+ }
+ if (desiredMatrix == GL_FALSE) {
+ /* Early error means all values are invalid. */
+ return 0xffff;
+ }
+
+ /* Now pull the matrix itself. */
+ _mesa_GetFloatv(desiredMatrix, matrix);
+
+ rv = 0;
+ for (i = 0, bit = 1; i < 16; i++, bit<<=1) {
+ float normalizedFraction;
+ int exp;
+
+ switch (fpclassify(matrix[i])) {
+ case FP_SUBNORMAL:
+ case FP_NORMAL:
+ case FP_ZERO:
+ /* A "subnormal" or denormalized number is too small to be
+ * represented in normal format; but despite that it's a
+ * valid floating point number. FP_ZERO and FP_NORMAL
+ * are both valid as well. We should be fine treating
+ * these three cases as legitimate floating-point numbers.
+ */
+ normalizedFraction = (GLfloat)frexp(matrix[i], &exp);
+ mantissa[i] = FLOAT_TO_FIXED(normalizedFraction);
+ exponent[i] = (GLint) exp;
+ break;
+
+ case FP_NAN:
+ /* If the entry is not-a-number or an infinity, then the
+ * matrix component is invalid. The invalid flag for
+ * the component is already set; might as well set the
+ * other return values to known values. We'll set
+ * distinct values so that a savvy end user could determine
+ * whether the matrix component was a NaN or an infinity,
+ * but this is more useful for debugging than anything else
+ * since the standard doesn't specify any such magic
+ * values to return.
+ */
+ mantissa[i] = INT_TO_FIXED(0);
+ exponent[i] = (GLint) 0;
+ rv |= bit;
+ break;
+
+ case FP_INFINITE:
+ /* Return +/- 1 based on whether it's a positive or
+ * negative infinity.
+ */
+ if (matrix[i] > 0) {
+ mantissa[i] = INT_TO_FIXED(1);
+ }
+ else {
+ mantissa[i] = -INT_TO_FIXED(1);
+ }
+ exponent[i] = (GLint) 0;
+ rv |= bit;
+ break;
+
+ default:
+ /* We should never get here; but here's a catching case
+ * in case fpclassify() is returnings something unexpected.
+ */
+ mantissa[i] = INT_TO_FIXED(2);
+ exponent[i] = (GLint) 0;
+ rv |= bit;
+ break;
+ }
+
+ } /* for each component */
+
+ /* All done */
+ return rv;
}