summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-05-12 13:38:13 -0600
committerBrian Paul <brianp@vmware.com>2009-05-12 13:38:13 -0600
commitede693ebf6b851c8289ecf836738bf1cdce343bf (patch)
treeb43ecb98d040346457a2fe85e3ef8d0d812e0159
parentaacfc96528edc4ca006e01b5e4cbb308781fc6fa (diff)
es: common files for ES 1.x and ES 2.x
-rw-r--r--src/gallium/state_trackers/es/es-common/Makefile.gnu46
-rw-r--r--src/gallium/state_trackers/es/es-common/st_cpaltex.c216
-rw-r--r--src/gallium/state_trackers/es/es-common/st_cpaltex.h20
-rw-r--r--src/gallium/state_trackers/es/es-common/st_fbo.c39
-rw-r--r--src/gallium/state_trackers/es/es-common/st_glapi.c92
-rw-r--r--src/gallium/state_trackers/es/es-common/st_glapientry.h57
-rw-r--r--src/gallium/state_trackers/es/es-common/st_platform.h48
-rw-r--r--src/gallium/state_trackers/es/es-common/st_query_matrix.c197
-rw-r--r--src/gallium/state_trackers/es/es-common/st_teximage.c90
-rw-r--r--src/gallium/state_trackers/es/es-common/st_threads.h34
-rw-r--r--src/gallium/state_trackers/es/es-common/st_winsys.h48
11 files changed, 887 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/es/es-common/Makefile.gnu b/src/gallium/state_trackers/es/es-common/Makefile.gnu
new file mode 100644
index 0000000000..859c486fc5
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/Makefile.gnu
@@ -0,0 +1,46 @@
+#----------------------------------------------------------------------------
+#
+# Copyright (2008). Intel Corporation.
+#
+# Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+# develop this driver.
+#
+# The source code contained or described herein and all documents
+# related to the source code ("Material") are owned by Intel
+# Corporation or its suppliers or licensors. Title to the Material
+# remains with Intel Corporation or it suppliers and licensors. The
+# Material contains trade secrets and proprietary and confidential
+# information of Intel or its suppliers and licensors. The Material is
+# protected by worldwide copyright and trade secret laws and
+# treaty provisions. No part of the Material may be used, copied,
+# reproduced, modified, published, uploaded, posted, transmitted,
+# distributed, or disclosed in any way without Intels prior express
+# written permission.
+#
+# No license under any patent, copyright, trade secret or other
+# intellectual property right is granted to or conferred upon you by
+# disclosure or delivery of the Materials, either expressly, by
+# implication, inducement, estoppel or otherwise. Any license
+# under such intellectual property rights must be express
+# and approved by Intel in writing.
+#
+#----------------------------------------------------------------------------
+LIB = gallium_es_common
+SUBLIB = gallium_es_common
+
+SOURCES = st_cpaltex.c \
+ st_glapi.c \
+ st_query_matrix.c \
+ st_teximage.c \
+ st_fbo.c
+
+HEADERS =
+
+PROJECT_INCLUDES = \
+ ../mesa \
+ ../mesa/state_tracker \
+ $(GALLIUM)/src/gallium/auxiliary \
+ $(GALLIUM)/src/gallium/include \
+ $(GALLIUM)/include
+
+include ../Makefile.include
diff --git a/src/gallium/state_trackers/es/es-common/st_cpaltex.c b/src/gallium/state_trackers/es/es-common/st_cpaltex.c
new file mode 100644
index 0000000000..a6941e96f4
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_cpaltex.c
@@ -0,0 +1,216 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+/**
+ * Code to convert compressed/paletted texture images to ordinary 4-byte RGBA.
+ * See the GL_OES_compressed_paletted_texture spec at
+ * http://khronos.org/registry/gles/extensions/OES/OES_compressed_paletted_texture.txt
+ */
+
+
+#include <assert.h>
+#include <stdlib.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include "st_cpaltex.h"
+
+
+
+extern void GL_APIENTRY
+_mesa_TexImage2D( GLenum target, GLint level, GLint internalformat,
+ GLsizei width, GLsizei height, GLint border,
+ GLenum format, GLenum type, const GLvoid *pixels );
+
+
+static const struct {
+ GLenum format;
+ GLuint palette_size;
+ GLuint size;
+} formats[] = {
+ { GL_PALETTE4_RGB8_OES, 16, 3 },
+ { GL_PALETTE4_RGBA8_OES, 16, 4 },
+ { GL_PALETTE4_R5_G6_B5_OES, 16, 2 },
+ { GL_PALETTE4_RGBA4_OES, 16, 2 },
+ { GL_PALETTE4_RGB5_A1_OES, 16, 2 },
+ { GL_PALETTE8_RGB8_OES, 256, 3 },
+ { GL_PALETTE8_RGBA8_OES, 256, 4 },
+ { GL_PALETTE8_R5_G6_B5_OES, 256, 2 },
+ { GL_PALETTE8_RGBA4_OES, 256, 2 },
+ { GL_PALETTE8_RGB5_A1_OES, 256, 2 }
+};
+
+
+/**
+ * Get a color/entry from the palette. Convert to GLubyte/RGBA format.
+ */
+static void
+get_palette_entry(GLenum format, const void *palette, GLuint index,
+ GLubyte rgba[4])
+{
+ switch (format) {
+ case GL_PALETTE4_RGB8_OES:
+ case GL_PALETTE8_RGB8_OES:
+ {
+ const GLubyte *pal = (const GLubyte *) palette;
+ rgba[0] = pal[index * 3 + 0];
+ rgba[1] = pal[index * 3 + 1];
+ rgba[2] = pal[index * 3 + 2];
+ rgba[3] = 255;
+ }
+ break;
+ case GL_PALETTE4_RGBA8_OES:
+ case GL_PALETTE8_RGBA8_OES:
+ {
+ const GLubyte *pal = (const GLubyte *) palette;
+ rgba[0] = pal[index * 4 + 0];
+ rgba[1] = pal[index * 4 + 1];
+ rgba[2] = pal[index * 4 + 2];
+ rgba[3] = pal[index * 4 + 3];
+ }
+ break;
+ case GL_PALETTE4_R5_G6_B5_OES:
+ case GL_PALETTE8_R5_G6_B5_OES:
+ {
+ const GLushort *pal = (const GLushort *) palette;
+ const GLushort color = pal[index];
+ rgba[0] = ((color >> 8) & 0xf8) | ((color >> 11) & 0x3);
+ rgba[1] = ((color >> 3) & 0xfc) | ((color >> 1 ) & 0x3);
+ rgba[2] = ((color << 3) & 0xf8) | ((color ) & 0x7);
+ rgba[3] = 255;
+ }
+ break;
+ case GL_PALETTE4_RGBA4_OES:
+ case GL_PALETTE8_RGBA4_OES:
+ {
+ const GLushort *pal = (const GLushort *) palette;
+ const GLushort color = pal[index];
+ rgba[0] = ((color & 0xf000) >> 8) | ((color & 0xf000) >> 12);
+ rgba[1] = ((color & 0x0f00) >> 4) | ((color & 0x0f00) >> 8);
+ rgba[2] = ((color & 0x00f0) ) | ((color & 0x00f0) >> 4);
+ rgba[3] = ((color & 0x000f) << 4) | ((color & 0x000f) );
+ }
+ break;
+ case GL_PALETTE4_RGB5_A1_OES:
+ case GL_PALETTE8_RGB5_A1_OES:
+ {
+ const GLushort *pal = (const GLushort *) palette;
+ const GLushort color = pal[index];
+ rgba[0] = ((color >> 8) & 0xf8) | ((color >> 11) & 0x7);
+ rgba[1] = ((color >> 3) & 0xf8) | ((color >> 6) & 0x7);
+ rgba[2] = ((color << 2) & 0xf8) | ((color >> 1) & 0x7);
+ rgba[3] = (color & 0x1) * 255;
+ }
+ break;
+ default:
+ assert(0);
+ }
+}
+
+
+/**
+ * Convert paletted texture to simple GLubyte/RGBA format.
+ */
+static void
+paletted_to_rgba(GLenum src_format,
+ const void *palette,
+ const void *indexes,
+ GLsizei width, GLsizei height,
+ GLubyte *rgba)
+{
+ GLuint pal_ents, i;
+
+ assert(src_format >= GL_PALETTE4_RGB8_OES);
+ assert(src_format <= GL_PALETTE8_RGB5_A1_OES);
+ assert(formats[src_format - GL_PALETTE4_RGB8_OES].format == src_format);
+
+ pal_ents = formats[src_format - GL_PALETTE4_RGB8_OES].palette_size;
+
+ if (pal_ents == 16) {
+ /* 4 bits per index */
+ const GLubyte *ind = (const GLubyte *) indexes;
+
+ if (width * height == 1) {
+ /* special case the only odd-sized image */
+ GLuint index0 = ind[0] >> 4;
+ get_palette_entry(src_format, palette, index0, rgba);
+ return;
+ }
+ /* two pixels per iteration */
+ for (i = 0; i < width * height / 2; i++) {
+ GLuint index0 = ind[i] >> 4;
+ GLuint index1 = ind[i] & 0xf;
+ get_palette_entry(src_format, palette, index0, rgba + i * 8);
+ get_palette_entry(src_format, palette, index1, rgba + i * 8 + 4);
+ }
+ }
+ else {
+ /* 8 bits per index */
+ const GLubyte *ind = (const GLubyte *) indexes;
+ for (i = 0; i < width * height; i++) {
+ GLuint index = ind[i];
+ get_palette_entry(src_format, palette, index, rgba + i * 4);
+ }
+ }
+}
+
+
+/**
+ * Convert a call to glCompressedTexImage2D() where internalFormat is a
+ * compressed palette format into a regular GLubyte/RGBA glTexImage2D() call.
+ */
+void
+cpal_compressed_teximage2d(GLenum target, GLint level,
+ GLenum internalFormat,
+ GLsizei width, GLsizei height,
+ const void *pixels)
+{
+ GLuint pal_ents, pal_ent_size, pal_bytes;
+ const GLint num_levels = level + 1;
+ GLint lvl;
+ const GLubyte *indexes;
+
+ assert(internalFormat >= GL_PALETTE4_RGB8_OES);
+ assert(internalFormat <= GL_PALETTE8_RGB5_A1_OES);
+ assert(formats[internalFormat - GL_PALETTE4_RGB8_OES].format == internalFormat);
+
+ pal_ents = formats[internalFormat - GL_PALETTE4_RGB8_OES].palette_size;
+ pal_ent_size = formats[internalFormat - GL_PALETTE4_RGB8_OES].size;
+ pal_bytes = pal_ents * pal_ent_size;
+
+ /* first image follows the palette */
+ indexes = (const GLubyte *) pixels + pal_bytes;
+
+ /* No worries about glPixelStore state since the only supported parameter is
+ * GL_UNPACK_ALIGNMENT and it doesn't matter when unpacking GLubyte/RGBA.
+ */
+
+ for (lvl = 0; lvl < num_levels; lvl++) {
+ /* Allocate GLubyte/RGBA dest image buffer */
+ GLubyte *rgba = (GLubyte *) malloc(width * height * 4);
+
+ if (pixels)
+ paletted_to_rgba(internalFormat, pixels, indexes, width, height, rgba);
+
+ _mesa_TexImage2D(target, lvl, GL_RGBA, width, height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, rgba);
+
+ free(rgba);
+
+ /* advance index pointer to point to next src mipmap */
+ if (pal_ents == 4)
+ indexes += width * height / 2;
+ else
+ indexes += width * height;
+
+ /* next mipmap level size */
+ if (width > 1)
+ width /= 2;
+ if (height > 1)
+ height /= 2;
+ }
+}
diff --git a/src/gallium/state_trackers/es/es-common/st_cpaltex.h b/src/gallium/state_trackers/es/es-common/st_cpaltex.h
new file mode 100644
index 0000000000..070439c68a
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_cpaltex.h
@@ -0,0 +1,20 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+#ifndef ST_CPALTEX_H
+#define ST_CPALTEX_H
+
+
+extern void
+cpal_compressed_teximage2d(GLenum target, GLint level,
+ GLenum internalFormat,
+ GLsizei width, GLsizei height,
+ const void *pixels);
+
+
+#endif /* ST_CPALTEX_H */
diff --git a/src/gallium/state_trackers/es/es-common/st_fbo.c b/src/gallium/state_trackers/es/es-common/st_fbo.c
new file mode 100644
index 0000000000..c50a54cf3c
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_fbo.c
@@ -0,0 +1,39 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ **************************************************************************/
+
+
+#include <stdlib.h>
+#include "GLES2/gl2.h"
+#include "GLES2/gl2ext.h"
+#include "st_platform.h"
+
+
+
+ST_IMPORT void ST_APIENTRY
+_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height);
+
+
+GL_APICALL void GL_APIENTRY
+glRenderbufferStorage(GLenum target, GLenum internalFormat,
+ GLsizei width, GLsizei height)
+{
+ switch (internalFormat) {
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGB565:
+ internalFormat = GL_RGBA;
+ break;
+ case GL_STENCIL_INDEX1_OES:
+ case GL_STENCIL_INDEX4_OES:
+ case GL_STENCIL_INDEX8:
+ internalFormat = GL_STENCIL_INDEX;
+ break;
+ default:
+ ; /* no op */
+ }
+ _mesa_RenderbufferStorageEXT(target, internalFormat, width, height);
+}
diff --git a/src/gallium/state_trackers/es/es-common/st_glapi.c b/src/gallium/state_trackers/es/es-common/st_glapi.c
new file mode 100644
index 0000000000..aa70d429e8
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_glapi.c
@@ -0,0 +1,92 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+/**
+ * API/dispatch management functions.
+ *
+ * These replace Mesa's regular glapi.c file.
+ *
+ * Note that we don't use an API dispatch table at all for the OpenGL
+ * ES state trackers. glEnable(), for example, directly calls the
+ * corresponding _mesa_Enable() function without going through a jump table.
+ *
+ * So the dispatch table stuff here is no-op'd.
+ *
+ * At this time, the current context pointer is _not_ thread safe.
+ */
+
+
+#include "glapi/glapi.h"
+
+
+void *_glapi_Context = NULL;
+
+struct _glapi_table *_glapi_Dispatch = NULL;
+
+
+void
+_glapi_noop_enable_warnings(GLboolean enable)
+{
+ /* no-op */
+}
+
+void
+_glapi_set_warning_func(_glapi_warning_func func)
+{
+ /* no-op */
+}
+
+
+void
+_glapi_check_multithread(void)
+{
+ /* no-op */
+}
+
+
+void
+_glapi_set_context(void *context)
+{
+ _glapi_Context = context;
+}
+
+
+void *
+_glapi_get_context(void)
+{
+ return _glapi_Context;
+}
+
+void
+_glapi_set_dispatch(struct _glapi_table *dispatch)
+{
+ /* no-op */
+}
+
+
+struct _glapi_table *
+_glapi_get_dispatch(void)
+{
+ return NULL;
+}
+
+
+GLuint
+_glapi_get_dispatch_table_size(void)
+{
+ return 0;
+}
+
+
+int
+_glapi_add_dispatch( const char * const * function_names,
+ const char * parameter_signature )
+{
+ /* we don't support run-time generation of new GL entrypoints */
+ return -1;
+}
diff --git a/src/gallium/state_trackers/es/es-common/st_glapientry.h b/src/gallium/state_trackers/es/es-common/st_glapientry.h
new file mode 100644
index 0000000000..2036390039
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_glapientry.h
@@ -0,0 +1,57 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.1
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ *
+ * 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 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
+ * BRIAN PAUL 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.
+ */
+
+#ifndef ST_GLAPIENTRY_H
+#define ST_GLAPIENTRY_H
+
+#if !defined(OPENSTEP) && (defined(NeXT) || defined(NeXT_PDO))
+#define OPENSTEP
+#endif
+
+#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__)
+#define __WIN32__
+#endif
+
+#if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__))
+# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */
+# define GLAPI __declspec(dllexport)
+# elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */
+# define GLAPI __declspec(dllimport)
+# else /* for use with static link lib build of Win32 edition only */
+# define GLAPI extern
+# endif /* _STATIC_MESA support */
+# if defined(__MINGW32__) && defined(GL_NO_STDCALL) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */
+# define GLAPIENTRY
+# else
+# define GLAPIENTRY __stdcall
+# endif
+#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */
+# define GLAPI extern
+# define GLAPIENTRY __stdcall
+#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
+# define GLAPI __attribute__((visibility("default")))
+# define GLAPIENTRY
+#endif /* WIN32 && !CYGWIN */
+
+#endif /* ST_GLAPIENTRY_H */
diff --git a/src/gallium/state_trackers/es/es-common/st_platform.h b/src/gallium/state_trackers/es/es-common/st_platform.h
new file mode 100644
index 0000000000..4c0409213b
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_platform.h
@@ -0,0 +1,48 @@
+#ifndef ST_PLATFORM_H
+#define ST_PLATFORM_H
+
+/* The irregular use of GL_API, GL_APIENTRY, APIENTRY, and other
+ * similar macros is making the build difficult, particularly on
+ * Windows.
+ *
+ * One particular issue is that GL_API has two different meanings,
+ * depending on whether you intend to use a header to create
+ * a library by defining its entry points, or whether you
+ * are using the header in the more traditional sense, to allow
+ * access and use of those same functions. Unfortunately for
+ * us, we *both* intend to create GLES entry points, and *also*
+ * use OpenGL/Mesa entry points. Since we're both importing
+ * and exporting, GL_API is broken.
+ *
+ * APIENTRY, GLAPIENTRY, and GL_APIENTRY are broken for logistic
+ * reasons; some are defined on some platforms, some not, and
+ * they're inconsistently used.
+ *
+ * This header will be used for the time being; it defines *three*
+ * macros, one for functions being imported, one for functions being
+ * exported, and one for call protocol.
+ *
+ * At some time, all the uses of these macros and their GL_*
+ * counterparts should be examined and unified.
+ */
+
+#if defined(WIN32) || defined(_WIN32_WCE)
+
+/*#define ST_IMPORT __declspec(dllimport)*/
+#define ST_IMPORT
+#define ST_EXPORT __declspec(dllexport)
+#if defined(UNDER_CE)
+#define ST_APIENTRY
+#else
+#define ST_APIENTRY __stdcall
+#endif
+
+#else
+
+#define ST_IMPORT extern
+#define ST_EXPORT
+#define ST_APIENTRY
+
+#endif
+
+#endif /* ST_PLATFORM_H */
diff --git a/src/gallium/state_trackers/es/es-common/st_query_matrix.c b/src/gallium/state_trackers/es/es-common/st_query_matrix.c
new file mode 100644
index 0000000000..a301efb292
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_query_matrix.c
@@ -0,0 +1,197 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+/**
+ * Code to implement GL_OES_query_matrix. See the spec at:
+ * http://www.khronos.org/registry/gles/extensions/OES/OES_query_matrix.txt
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GLES/gl.h>
+#define GL_GLEXT_PROTOTYPES
+#include <GLES/glext.h>
+#include "st_platform.h"
+
+/**
+ * This is from the GL_OES_query_matrix extension specification:
+ *
+ * GLbitfield glQueryMatrixxOES( GLfixed mantissa[16],
+ * GLint exponent[16] )
+ * mantissa[16] contains the contents of the current matrix in GLfixed
+ * format. exponent[16] contains the unbiased exponents applied to the
+ * matrix components, so that the internal representation of component i
+ * is close to mantissa[i] * 2^exponent[i]. The function returns a status
+ * word which is zero if all the components are valid. If
+ * status & (1<<i) != 0, the component i is invalid (e.g., NaN, Inf).
+ * The implementations are not required to keep track of overflows. In
+ * that case, the invalid bits are never set.
+ */
+
+#define INT_TO_FIXED(x) ((GLfixed) ((x) << 16))
+#define FLOAT_TO_FIXED(x) ((GLfixed) ((x) * 65536.0))
+
+#if defined(WIN32) || defined(_WIN32_WCE)
+/* Oddly, the fpclassify() function doesn't exist in such a form
+ * on Windows. 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;
+ }
+}
+#endif
+
+/* The Mesa functions we'll need */
+ST_IMPORT void ST_APIENTRY _mesa_GetIntegerv(GLenum pname, GLint *params);
+ST_IMPORT void ST_APIENTRY _mesa_GetFloatv(GLenum pname, GLfloat *params);
+
+ST_EXPORT GLbitfield ST_APIENTRY glQueryMatrixxOES(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},
+#if 0
+ /* this doesn't exist in GLES */
+ {GL_COLOR, GL_COLOR_MATRIX},
+#endif
+ };
+
+ /* 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;
+}
diff --git a/src/gallium/state_trackers/es/es-common/st_teximage.c b/src/gallium/state_trackers/es/es-common/st_teximage.c
new file mode 100644
index 0000000000..3a19a65872
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_teximage.c
@@ -0,0 +1,90 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+/**
+ * Special ES texture image functions, for both ES1 and ES2.
+ */
+
+
+#include "GLES/glplatform.h"
+
+//#include "main/teximage.h" // Don't include these because one of them pulls in gl.h
+//#include "st_cpaltex.h"
+
+
+
+/*
+ * typedefs/etc from GLES/gl.h here. Can't include that header because
+ * it generates tons of conflicts.
+ */
+
+#ifndef GL_OES_compressed_paletted_texture
+
+#define GL_PALETTE4_RGB8_OES 0x8B90
+#define GL_PALETTE4_RGBA8_OES 0x8B91
+#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
+#define GL_PALETTE4_RGBA4_OES 0x8B93
+#define GL_PALETTE4_RGB5_A1_OES 0x8B94
+#define GL_PALETTE8_RGB8_OES 0x8B95
+#define GL_PALETTE8_RGBA8_OES 0x8B96
+#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
+#define GL_PALETTE8_RGBA4_OES 0x8B98
+#define GL_PALETTE8_RGB5_A1_OES 0x8B99
+#endif
+
+typedef unsigned int GLenum;
+typedef unsigned char GLboolean;
+typedef unsigned int GLbitfield;
+typedef signed char GLbyte;
+typedef short GLshort;
+typedef int GLint;
+typedef int GLsizei;
+typedef unsigned char GLubyte;
+typedef unsigned short GLushort;
+typedef unsigned int GLuint;
+typedef float GLfloat;
+typedef float GLclampf;
+typedef void GLvoid;
+typedef int GLintptr;
+typedef int GLsizeiptr;
+typedef int GLfixed;
+typedef int GLclampx;
+/* Internal convenience typedefs */
+typedef void (*_GLfuncptr)();
+
+void GL_APIENTRY
+_mesa_CompressedTexImage2DARB(GLenum target, GLint level,
+ GLenum internalformat, GLsizei width,
+ GLsizei height, GLint border, GLsizei imageSize,
+ const GLvoid *data);
+
+GL_API void GL_APIENTRY
+glCompressedTexImage2D(GLenum target, GLint level, GLenum internalFormat,
+ GLsizei width, GLsizei height, GLint border,
+ GLsizei imageSize, const GLvoid *data)
+{
+ switch (internalFormat) {
+ case GL_PALETTE4_RGB8_OES:
+ case GL_PALETTE4_RGBA8_OES:
+ case GL_PALETTE4_R5_G6_B5_OES:
+ case GL_PALETTE4_RGBA4_OES:
+ case GL_PALETTE4_RGB5_A1_OES:
+ case GL_PALETTE8_RGB8_OES:
+ case GL_PALETTE8_RGBA8_OES:
+ case GL_PALETTE8_R5_G6_B5_OES:
+ case GL_PALETTE8_RGBA4_OES:
+ case GL_PALETTE8_RGB5_A1_OES:
+ cpal_compressed_teximage2d(target, level, internalFormat,
+ width, height, data);
+ break;
+ default:
+ _mesa_CompressedTexImage2DARB(target, level, internalFormat,
+ width, height, border, imageSize, data);
+ }
+}
+
diff --git a/src/gallium/state_trackers/es/es-common/st_threads.h b/src/gallium/state_trackers/es/es-common/st_threads.h
new file mode 100644
index 0000000000..847ae81f8a
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_threads.h
@@ -0,0 +1,34 @@
+#ifndef ST_THREADS_H
+#define ST_THREADS_H
+
+/* Macro access to thread-local storage.
+ *
+ * Variables holding keys should be of type TLS_KEY_TYPE.
+ * To allocate a new key, use TLS_ALLOC_KEY(), which will return
+ * true if the key was allocated successfully:
+ * TLS_KEY_TYPE key;
+ * if (!TLS_ALLOC_KEY(key, NULL)) {
+ * error("Couldn't allocate a key");
+ * return;
+ * }
+ * TLS_DELETE_KEY() releases a key, returning true if successful.
+ * TLS_SET_VALUE(key, value) sets the value of the key, returning true if successful.
+ * TLS_GET_VALUE(key) returns the value of a key.
+ */
+#if (defined(WIN32) || defined(_WIN32_WCE))
+#include <windows.h>
+#define TLS_KEY_TYPE DWORD
+#define TLS_ALLOC_KEY(key, destructor) ((key = TlsAlloc()) != 0xffffffff)
+#define TLS_DELETE_KEY(key) (TlsFree(key) != 0)
+#define TLS_SET_VALUE(key,value) (TlsSetValue(key,(void *)value) != 0)
+#define TLS_GET_VALUE(key) TlsGetValue(key)
+#else
+#include <pthread.h>
+#define TLS_KEY_TYPE pthread_key_t
+#define TLS_ALLOC_KEY(key, destructor) (pthread_key_create(&key, destructor) == 0)
+#define TLS_DELETE_KEY(key) (pthread_key_delete(key) == 0)
+#define TLS_SET_VALUE(key,value) (pthread_setspecific(key,(void *)value) == 0)
+#define TLS_GET_VALUE(key) pthread_getspecific(key)
+#endif
+
+#endif /* ST_THREADS_H */
diff --git a/src/gallium/state_trackers/es/es-common/st_winsys.h b/src/gallium/state_trackers/es/es-common/st_winsys.h
new file mode 100644
index 0000000000..bcfcf68fb2
--- /dev/null
+++ b/src/gallium/state_trackers/es/es-common/st_winsys.h
@@ -0,0 +1,48 @@
+/**************************************************************************
+ *
+ * Copyright 2007-2008, Tungsten Graphics, Inc. All rights reserved.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * Public interface for the EGL/ES state tracker.
+ *
+ * @author Jonathan White <jwhite@tungstengraphics.com>
+ */
+
+#ifndef ST_WINSYS_H
+#define ST_WINSYS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct pipe_winsys;
+struct pipe_context;
+struct pipe_winsys;
+struct iegd_gdi_window;
+struct ial_dev_priv;
+
+/**
+ * EGL/ES state tracker interface.
+ *
+ * Gallium3D's EGL/ES state tracker interface
+ */
+struct st_winsys
+{
+ /** Create a pipe context */
+ struct pipe_context * (*create_context)(struct pipe_screen *screen);
+
+ /** Alloc iegd_gdi_window hold EGL NativeWindowType return EGLRect in window **/
+ struct iegd_gdi_surface * (*alloc_window_surface)(struct win32_egl_surface *window);
+
+ /** Free iegd_gdi_surface and related GDI Windows surfaces */
+ void (*free_window_surface)(struct iegd_gdi_surface *gwnd);
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ST_WINSYS_H */