summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2009-09-22 15:00:24 +0800
committerBrian Paul <[email protected]>2009-11-05 20:04:20 -0700
commit34064756a5e2c8952c9de26eaebafddabd562540 (patch)
treeafb8aa9358db033b672db8b69f7dabbb4ec800a1
parentbfa66bd6f941920cf32ce79fb103c3755b4dd8fb (diff)
mesa/es: Add support for GL_OES_draw_texture.
Signed-off-by: Chia-I Wu <[email protected]>
-rw-r--r--src/mesa/es/main/APIspec.txt77
-rw-r--r--src/mesa/es/main/drawtex.c148
-rw-r--r--src/mesa/es/main/drawtex.h77
-rw-r--r--src/mesa/es/main/mfeatures_es1.h1
-rw-r--r--src/mesa/es/main/mfeatures_es2.h1
-rw-r--r--src/mesa/es/main/specials_es1.c5
-rw-r--r--src/mesa/es/sources.mak4
-rw-r--r--src/mesa/es/state_tracker/st_cb_drawtex.c297
-rw-r--r--src/mesa/es/state_tracker/st_cb_drawtex.h18
-rw-r--r--src/mesa/main/dd.h10
-rw-r--r--src/mesa/main/extensions.c3
-rw-r--r--src/mesa/main/mtypes.h3
-rw-r--r--src/mesa/state_tracker/st_context.c9
-rw-r--r--src/mesa/state_tracker/st_extensions.c4
14 files changed, 654 insertions, 3 deletions
diff --git a/src/mesa/es/main/APIspec.txt b/src/mesa/es/main/APIspec.txt
index 86dd546f634..6d18ae67d9f 100644
--- a/src/mesa/es/main/APIspec.txt
+++ b/src/mesa/es/main/APIspec.txt
@@ -412,6 +412,8 @@ checkdependentparam pname GL_TEXTURE_WRAP_T params GLES1.1:GL_MIRRORED_REPEAT_OE
dependentvector params 1 pname GL_TEXTURE_MAX_ANISOTROPY_EXT
# OES_texture_3D
checkdependentparam pname GL_TEXTURE_WRAP_R_OES params GLES2.0:GL_CLAMP_TO_EDGE GLES2.0:GL_REPEAT GLES2.0:GL_MIRRORED_REPEAT
+# OES_draw_texture - not in gl2ext.h
+dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
category GLES1.1 GLES2.0
name TexParameteri
@@ -457,6 +459,8 @@ checkdependentparam pname GL_TEXTURE_WRAP_T params GLES1.1:GL_MIRRORED_REPEAT_OE
dependentvector params 1 pname GL_TEXTURE_MAX_ANISOTROPY_EXT
# OES_texture_3D
checkdependentparam pname GL_TEXTURE_WRAP_R_OES params GLES2.0:GL_CLAMP_TO_EDGE GLES2.0:GL_REPEAT GLES2.0:GL_MIRRORED_REPEAT
+# OES_draw_texture - not in gl2ext.h
+dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
category GLES1.1 GLES2.0
name TexParameterx
@@ -498,6 +502,8 @@ checkdependentparam pname GL_TEXTURE_MAG_FILTER params GL_NEAREST GL_LINEAR
checkdependentparam pname GL_GENERATE_MIPMAP params GL_TRUE GL_FALSE
convertalias TexParameterfv
convertparams GLfloat params
+# OES_draw_texture
+dependentvector params 4 pname GL_TEXTURE_CROP_RECT_OES
# OES_texture_cube_map
checkparam target GL_TEXTURE_CUBE_MAP_OES
# OES_texture_mirrored_repeat
@@ -1352,6 +1358,8 @@ param pname GLenum
param params GLfloat *
dependentvector params 1 pname GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXTURE_MIN_FILTER GL_TEXTURE_MAG_FILTER GLES1.1:GL_GENERATE_MIPMAP
props get
+# OES_draw_texture - not in gl2ext.h
+dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
# OES_texture_cube_map
checkparam target GLES1.1:GL_TEXTURE_CUBE_MAP_OES
category GLES1.1 GLES2.0
@@ -1366,6 +1374,8 @@ dependentvector params 1 pname GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXTURE_MI
props get
# OES_texture_cube_map
checkparam target GLES1.1:GL_TEXTURE_CUBE_MAP_OES
+# OES_draw_texture - not in gl2ext.h
+dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
# OES_texture_3D
checkparam target GLES2.0:GL_TEXTURE_3D_OES
category GLES1.1 GLES2.0
@@ -1383,6 +1393,8 @@ dependentnovalueconvert params pname GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXT
props get
# OES_texture_cube_map
checkparam target GL_TEXTURE_CUBE_MAP_OES
+# OES_draw_texture
+dependentvector params 4 pname GL_TEXTURE_CROP_RECT_OES
category GLES1.1 GLES1.1:OES_fixed_point
# GLES1.1 and GLES2.0 have different capabilities
@@ -2867,6 +2879,71 @@ vector exponent 16
props get
category GLES1.1:OES_query_matrix
+# OES_draw_texture
+name DrawTexf
+return void
+param x GLfloat
+param y GLfloat
+param z GLfloat
+param w GLfloat
+param h GLfloat
+category GLES1.1:OES_draw_texture
+
+name DrawTexi
+return void
+param x GLint
+param y GLint
+param z GLint
+param w GLint
+param h GLint
+category GLES1.1:OES_draw_texture
+
+name DrawTexs
+return void
+param x GLshort
+param y GLshort
+param z GLshort
+param w GLshort
+param h GLshort
+category GLES1.1:OES_draw_texture
+
+name DrawTexx
+return void
+param x GLfixed
+param y GLfixed
+param z GLfixed
+param w GLfixed
+param h GLfixed
+convertalias DrawTexf
+convertparams GLfloat x y z w h
+category GLES1.1:OES_draw_texture
+
+name DrawTexfv
+return void
+param coords const GLfloat *
+vector coords 5
+category GLES1.1:OES_draw_texture
+
+name DrawTexiv
+return void
+param coords const GLint *
+vector coords 5
+category GLES1.1:OES_draw_texture
+
+name DrawTexsv
+return void
+param coords const GLshort *
+vector coords 5
+category GLES1.1:OES_draw_texture
+
+name DrawTexxv
+return void
+param coords const GLfixed *
+vector coords 5
+convertalias DrawTexfv
+convertparams GLfloat coords
+category GLES1.1:OES_draw_texture
+
# We don't support OES_get_program_binary yet either
#name GetProgramBinary
#return void
diff --git a/src/mesa/es/main/drawtex.c b/src/mesa/es/main/drawtex.c
new file mode 100644
index 00000000000..cbd41ca9759
--- /dev/null
+++ b/src/mesa/es/main/drawtex.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu <[email protected]>
+ *
+ * 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 "drawtex.h"
+#include "main/state.h"
+#include "main/imports.h"
+
+#include "glapi/dispatch.h"
+
+
+#if FEATURE_OES_draw_texture
+
+
+static void
+draw_texture(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z,
+ GLfloat width, GLfloat height)
+{
+ if (!ctx->Extensions.OES_draw_texture) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawTex(unsupported)");
+ return;
+ }
+ if (width <= 0.0f || height <= 0.0f) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glDrawTex(width or height <= 0)");
+ return;
+ }
+
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ ASSERT(ctx->Driver.DrawTex);
+ ctx->Driver.DrawTex(ctx, x, y, z, width, height);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx, x, y, z, width, height);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexfv(const GLfloat *coords)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx, coords[0], coords[1], coords[2], coords[3], coords[4]);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
+ (GLfloat) width, (GLfloat) height);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexiv(const GLint *coords)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
+ (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
+ (GLfloat) width, (GLfloat) height);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexsv(const GLshort *coords)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
+ (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx,
+ (GLfloat) x / 65536.0f,
+ (GLfloat) y / 65536.0f,
+ (GLfloat) z / 65536.0f,
+ (GLfloat) width / 65536.0f,
+ (GLfloat) height / 65536.0f);
+}
+
+
+void GLAPIENTRY
+_mesa_DrawTexxv(const GLfixed *coords)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ draw_texture(ctx,
+ (GLfloat) coords[0] / 65536.0f,
+ (GLfloat) coords[1] / 65536.0f,
+ (GLfloat) coords[2] / 65536.0f,
+ (GLfloat) coords[3] / 65536.0f,
+ (GLfloat) coords[4] / 65536.0f);
+}
+
+
+void
+_mesa_init_drawtex_dispatch(struct _glapi_table *disp)
+{
+ SET_DrawTexfOES(disp, _mesa_DrawTexf);
+ SET_DrawTexfvOES(disp, _mesa_DrawTexfv);
+ SET_DrawTexiOES(disp, _mesa_DrawTexi);
+ SET_DrawTexivOES(disp, _mesa_DrawTexiv);
+ SET_DrawTexsOES(disp, _mesa_DrawTexs);
+ SET_DrawTexsvOES(disp, _mesa_DrawTexsv);
+ SET_DrawTexxOES(disp, _mesa_DrawTexx);
+ SET_DrawTexxvOES(disp, _mesa_DrawTexxv);
+}
+
+
+#endif /* FEATURE_OES_draw_texture */
diff --git a/src/mesa/es/main/drawtex.h b/src/mesa/es/main/drawtex.h
new file mode 100644
index 00000000000..0f3bac38c77
--- /dev/null
+++ b/src/mesa/es/main/drawtex.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef DRAWTEX_H
+#define DRAWTEX_H
+
+
+#include "main/mtypes.h"
+
+
+#if FEATURE_OES_draw_texture
+
+#define _MESA_INIT_DRAWTEX_FUNCTIONS(driver, impl) \
+ do { \
+ (driver)->DrawTex = impl ## DrawTex; \
+ } while (0)
+
+extern void GLAPIENTRY
+_mesa_DrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
+
+extern void GLAPIENTRY
+_mesa_DrawTexfv(const GLfloat *coords);
+
+extern void GLAPIENTRY
+_mesa_DrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height);
+
+extern void GLAPIENTRY
+_mesa_DrawTexiv(const GLint *coords);
+
+extern void GLAPIENTRY
+_mesa_DrawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height);
+
+extern void GLAPIENTRY
+_mesa_DrawTexsv(const GLshort *coords);
+
+extern void GLAPIENTRY
+_mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height);
+
+extern void GLAPIENTRY
+_mesa_DrawTexxv(const GLfixed *coords);
+
+extern void
+_mesa_init_drawtex_dispatch(struct _glapi_table *disp);
+
+#else /* FEATURE_OES_draw_texture */
+
+#define _MESA_INIT_DRAWTEX_FUNCTIONS(driver, impl) do { } while (0)
+
+static INLINE void
+_mesa_init_drawtex_dispatch(struct _glapi_table *disp)
+{
+}
+
+#endif /* FEATURE_OES_draw_texture */
+
+
+#endif /* DRAWTEX_H */
diff --git a/src/mesa/es/main/mfeatures_es1.h b/src/mesa/es/main/mfeatures_es1.h
index 9c655960893..6c2ece26080 100644
--- a/src/mesa/es/main/mfeatures_es1.h
+++ b/src/mesa/es/main/mfeatures_es1.h
@@ -103,6 +103,7 @@
#define FEATURE_NV_vertex_program 0
#define FEATURE_OES_framebuffer_object 1
+#define FEATURE_OES_draw_texture 1
#define FEATURE_OES_mapbuffer 1
#define FEATURE_extra_context_init 1
diff --git a/src/mesa/es/main/mfeatures_es2.h b/src/mesa/es/main/mfeatures_es2.h
index 6ed7b678dcd..f34782fedb9 100644
--- a/src/mesa/es/main/mfeatures_es2.h
+++ b/src/mesa/es/main/mfeatures_es2.h
@@ -103,6 +103,7 @@
#define FEATURE_NV_vertex_program 0
#define FEATURE_OES_framebuffer_object 1
+#define FEATURE_OES_draw_texture 0
#define FEATURE_OES_mapbuffer 1
#define FEATURE_extra_context_init 1
diff --git a/src/mesa/es/main/specials_es1.c b/src/mesa/es/main/specials_es1.c
index 84d339ebf67..548fb0f0297 100644
--- a/src/mesa/es/main/specials_es1.c
+++ b/src/mesa/es/main/specials_es1.c
@@ -100,6 +100,11 @@ make_extension_string(const GLcontext *ctx, char *str)
/* 1.1 deprecated extensions */
len += append_extension(&str, "GL_OES_query_matrix");
+#if FEATURE_OES_draw_texture
+ if (ctx->Extensions.OES_draw_texture)
+ len += append_extension(&str, "GL_OES_draw_texture");
+#endif
+
if (ctx->Extensions.EXT_blend_equation_separate)
len += append_extension(&str, "GL_OES_blend_equation_separate");
if (ctx->Extensions.EXT_blend_func_separate)
diff --git a/src/mesa/es/sources.mak b/src/mesa/es/sources.mak
index d12acaae807..11f735d52af 100644
--- a/src/mesa/es/sources.mak
+++ b/src/mesa/es/sources.mak
@@ -4,6 +4,7 @@ include $(MESA)/sources.mak
LOCAL_ES1_SOURCES := \
main/api_exec_es1.c \
+ main/drawtex.c \
main/get_es1.c \
main/specials_es1.c \
main/drawtex.c \
@@ -14,7 +15,8 @@ LOCAL_ES1_SOURCES := \
glapi/glapi-es1/main/enums.c
LOCAL_ES1_GALLIUM_SOURCES := \
- $(LOCAL_ES1_SOURCES)
+ $(LOCAL_ES1_SOURCES) \
+ state_tracker/st_cb_drawtex.c
# always use local version of GLAPI_ASM_SOURCES
LOCAL_ES1_API_ASM := $(addprefix glapi/glapi-es1/, $(GLAPI_ASM_SOURCES))
diff --git a/src/mesa/es/state_tracker/st_cb_drawtex.c b/src/mesa/es/state_tracker/st_cb_drawtex.c
new file mode 100644
index 00000000000..3b98b9c40b3
--- /dev/null
+++ b/src/mesa/es/state_tracker/st_cb_drawtex.c
@@ -0,0 +1,297 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+/**
+ * Implementation of glDrawTex() for GL_OES_draw_tex
+ */
+
+
+
+#include "main/imports.h"
+#include "main/image.h"
+#include "main/bufferobj.h"
+#include "main/drawtex.h"
+#include "main/macros.h"
+#include "main/state.h"
+#include "main/texformat.h"
+#include "shader/program.h"
+#include "shader/prog_parameter.h"
+#include "shader/prog_print.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_atom_constbuf.h"
+#include "st_draw.h"
+#include "st_cb_drawtex.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_tile.h"
+#include "util/u_draw_quad.h"
+#include "util/u_simple_shaders.h"
+
+#include "cso_cache/cso_context.h"
+
+
+struct cached_shader
+{
+ //struct pipe_shader_state shader;
+ void *handle;
+
+ uint num_attribs;
+ uint semantic_names[2 + MAX_TEXTURE_UNITS];
+ uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
+};
+
+#define MAX_SHADERS (2 * MAX_TEXTURE_UNITS)
+
+/**
+ * Simple linear list cache.
+ * Most of the time there'll only be one cached shader.
+ */
+static struct cached_shader CachedShaders[MAX_SHADERS];
+static GLuint NumCachedShaders = 0;
+
+
+#if FEATURE_OES_draw_texture
+
+
+static void *
+lookup_shader(struct pipe_context *pipe,
+ uint num_attribs,
+ const uint *semantic_names,
+ const uint *semantic_indexes)
+{
+ GLuint i, j;
+
+ /* look for existing shader with same attributes */
+ for (i = 0; i < NumCachedShaders; i++) {
+ if (CachedShaders[i].num_attribs == num_attribs) {
+ GLboolean match = GL_TRUE;
+ for (j = 0; j < num_attribs; j++) {
+ if (semantic_names[j] != CachedShaders[i].semantic_names[j] ||
+ semantic_indexes[j] != CachedShaders[i].semantic_indexes[j]) {
+ match = GL_FALSE;
+ break;
+ }
+ }
+ if (match)
+ return CachedShaders[i].handle;
+ }
+ }
+
+ /* not found - create new one now */
+ if (NumCachedShaders >= MAX_SHADERS) {
+ return NULL;
+ }
+
+ CachedShaders[i].num_attribs = num_attribs;
+ for (j = 0; j < num_attribs; j++) {
+ CachedShaders[i].semantic_names[j] = semantic_names[j];
+ CachedShaders[i].semantic_indexes[j] = semantic_indexes[j];
+ }
+
+ CachedShaders[i].handle =
+ util_make_vertex_passthrough_shader(pipe,
+ num_attribs,
+ semantic_names,
+ semantic_indexes);
+ NumCachedShaders++;
+
+ return CachedShaders[i].handle;
+}
+
+static void
+st_DrawTex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z,
+ GLfloat width, GLfloat height)
+{
+ struct st_context *st = ctx->st;
+ struct pipe_context *pipe = st->pipe;
+ struct cso_context *cso = ctx->st->cso_context;
+ struct pipe_buffer *vbuffer;
+ GLuint i, numTexCoords, numAttribs;
+ GLboolean emitColor;
+ uint semantic_names[2 + MAX_TEXTURE_UNITS];
+ uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
+ GLbitfield inputs = VERT_BIT_POS;
+
+ /* determine if we need vertex color */
+ if (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL0)
+ emitColor = GL_TRUE;
+ else
+ emitColor = GL_FALSE;
+
+ /* determine how many enabled sets of texcoords */
+ numTexCoords = 0;
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+ if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
+ inputs |= VERT_BIT_TEX(i);
+ numTexCoords++;
+ }
+ }
+
+ /* total number of attributes per vertex */
+ numAttribs = 1 + emitColor + numTexCoords;
+
+
+ /* create the vertex buffer */
+ vbuffer = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
+ numAttribs * 4 * 4 * sizeof(GLfloat));
+
+ /* load vertex buffer */
+ {
+#define SET_ATTRIB(VERT, ATTR, X, Y, Z, W) \
+ do { \
+ GLuint k = (((VERT) * numAttribs + (ATTR)) * 4); \
+ assert(k < 4 * 4 * numAttribs); \
+ vbuf[k + 0] = X; \
+ vbuf[k + 1] = Y; \
+ vbuf[k + 2] = Z; \
+ vbuf[k + 3] = W; \
+ } while (0)
+
+ const GLfloat x0 = x, y0 = y, x1 = x + width, y1 = y + height;
+ GLfloat *vbuf = (GLfloat *) pipe_buffer_map(pipe->screen, vbuffer,
+ PIPE_BUFFER_USAGE_CPU_WRITE);
+ GLuint attr;
+
+ z = CLAMP(z, 0.0f, 1.0f);
+
+ /* positions (in clip coords) */
+ {
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLfloat fb_width = (GLfloat)fb->Width;
+ const GLfloat fb_height = (GLfloat)fb->Height;
+
+ const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
+ const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
+ const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
+ const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
+
+ SET_ATTRIB(0, 0, clip_x0, clip_y0, z, 1.0f); /* lower left */
+ SET_ATTRIB(1, 0, clip_x1, clip_y0, z, 1.0f); /* lower right */
+ SET_ATTRIB(2, 0, clip_x1, clip_y1, z, 1.0f); /* upper right */
+ SET_ATTRIB(3, 0, clip_x0, clip_y1, z, 1.0f); /* upper left */
+
+ semantic_names[0] = TGSI_SEMANTIC_POSITION;
+ semantic_indexes[0] = 0;
+ }
+
+ /* colors */
+ if (emitColor) {
+ const GLfloat *c = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
+ SET_ATTRIB(0, 1, c[0], c[1], c[2], c[3]);
+ SET_ATTRIB(1, 1, c[0], c[1], c[2], c[3]);
+ SET_ATTRIB(2, 1, c[0], c[1], c[2], c[3]);
+ SET_ATTRIB(3, 1, c[0], c[1], c[2], c[3]);
+ semantic_names[1] = TGSI_SEMANTIC_COLOR;
+ semantic_indexes[1] = 0;
+ attr = 2;
+ }
+ else {
+ attr = 1;
+ }
+
+ /* texcoords */
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+ if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
+ struct gl_texture_object *obj = ctx->Texture.Unit[i]._Current;
+ struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
+ const GLfloat wt = (GLfloat) img->Width;
+ const GLfloat ht = (GLfloat) img->Height;
+ const GLfloat s0 = obj->CropRect[0] / wt;
+ const GLfloat t0 = obj->CropRect[1] / ht;
+ const GLfloat s1 = (obj->CropRect[0] + obj->CropRect[2]) / wt;
+ const GLfloat t1 = (obj->CropRect[1] + obj->CropRect[3]) / ht;
+
+ /*printf("crop texcoords: %g, %g .. %g, %g\n", s0, t0, s1, t1);*/
+ SET_ATTRIB(0, attr, s0, t0, 0.0f, 1.0f); /* lower left */
+ SET_ATTRIB(1, attr, s1, t0, 0.0f, 1.0f); /* lower right */
+ SET_ATTRIB(2, attr, s1, t1, 0.0f, 1.0f); /* upper right */
+ SET_ATTRIB(3, attr, s0, t1, 0.0f, 1.0f); /* upper left */
+
+ semantic_names[attr] = TGSI_SEMANTIC_GENERIC;
+ semantic_indexes[attr] = 0;
+
+ attr++;
+ }
+ }
+
+ pipe_buffer_unmap(pipe->screen, vbuffer);
+
+#undef SET_ATTRIB
+ }
+
+
+ cso_save_viewport(cso);
+ cso_save_vertex_shader(cso);
+
+ {
+ void *vs = lookup_shader(pipe, numAttribs,
+ semantic_names, semantic_indexes);
+ cso_set_vertex_shader_handle(cso, vs);
+ }
+
+ /* viewport state: viewport matching window dims */
+ {
+ const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
+ const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
+ const GLfloat width = (GLfloat)fb->Width;
+ const GLfloat height = (GLfloat)fb->Height;
+ struct pipe_viewport_state vp;
+ vp.scale[0] = 0.5f * width;
+ vp.scale[1] = height * (invert ? -0.5f : 0.5f);
+ vp.scale[2] = 1.0f;
+ vp.scale[3] = 1.0f;
+ vp.translate[0] = 0.5f * width;
+ vp.translate[1] = 0.5f * height;
+ vp.translate[2] = 0.0f;
+ vp.translate[3] = 0.0f;
+ cso_set_viewport(cso, &vp);
+ }
+
+
+ util_draw_vertex_buffer(pipe, vbuffer,
+ 0, /* offset */
+ PIPE_PRIM_TRIANGLE_FAN,
+ 4, /* verts */
+ numAttribs); /* attribs/vert */
+
+
+ pipe_buffer_reference(&vbuffer, NULL);
+
+ /* restore state */
+ cso_restore_viewport(cso);
+ cso_restore_vertex_shader(cso);
+}
+
+
+#endif /* FEATURE_OES_draw_texture */
+
+
+void
+st_init_drawtex_functions(struct dd_function_table *functions)
+{
+ _MESA_INIT_DRAWTEX_FUNCTIONS(functions, st_);
+}
+
+
+/**
+ * Free any cached shaders
+ */
+void
+st_destroy_drawtex(struct st_context *st)
+{
+ GLuint i;
+ for (i = 0; i < NumCachedShaders; i++) {
+ cso_delete_vertex_shader(st->cso_context, CachedShaders[i].handle);
+ }
+ NumCachedShaders = 0;
+}
diff --git a/src/mesa/es/state_tracker/st_cb_drawtex.h b/src/mesa/es/state_tracker/st_cb_drawtex.h
new file mode 100644
index 00000000000..7b0da702798
--- /dev/null
+++ b/src/mesa/es/state_tracker/st_cb_drawtex.h
@@ -0,0 +1,18 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+
+#ifndef ST_CB_DRAWTEX_H
+#define ST_CB_DRAWTEX_H
+
+extern void
+st_init_drawtex_functions(struct dd_function_table *functions);
+
+extern void
+st_destroy_drawtex(struct st_context *st);
+
+#endif /* ST_CB_DRAWTEX_H */
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 99f2cad4028..0488a693b2b 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -1046,6 +1046,16 @@ struct dd_function_table {
GLbitfield, GLuint64);
/*@}*/
#endif
+
+#if FEATURE_OES_draw_texture
+ /**
+ * \name GL_OES_draw_texture interface
+ */
+ /*@{*/
+ void (*DrawTex)(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z,
+ GLfloat width, GLfloat height);
+ /*@}*/
+#endif
};
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 54cf37c5f48..7a8184ffc89 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -185,6 +185,9 @@ static const struct {
{ ON, "GL_SGIS_texture_lod", F(SGIS_texture_lod) },
{ ON, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) },
{ OFF, "GL_S3_s3tc", F(S3_s3tc) },
+#if FEATURE_OES_draw_texture
+ { OFF, "GL_OES_draw_texture", F(OES_draw_texture) },
+#endif /* FEATURE_OES_draw_texture */
};
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 94d29a7dbb6..e91c7e5ac16 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2485,6 +2485,9 @@ struct gl_extensions
GLboolean SGIS_texture_lod;
GLboolean TDFX_texture_compression_FXT1;
GLboolean S3_s3tc;
+#if FEATURE_OES_draw_texture
+ GLboolean OES_draw_texture;
+#endif /* FEATURE_OES_draw_texture */
/** The extension string */
const GLubyte *String;
};
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index f0eddafd331..e82598c8e7e 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -47,7 +47,7 @@
#include "st_cb_drawpixels.h"
#include "st_cb_rasterpos.h"
#endif
-#ifdef FEATURE_OES_draw_texture
+#if FEATURE_OES_draw_texture
#include "st_cb_drawtex.h"
#endif
#include "st_cb_fbo.h"
@@ -209,7 +209,7 @@ static void st_destroy_context_priv( struct st_context *st )
st_destroy_bitmap(st);
st_destroy_drawpix(st);
#endif
-#ifdef FEATURE_OES_draw_texture
+#if FEATURE_OES_draw_texture
st_destroy_drawtex(st);
#endif
@@ -330,6 +330,11 @@ void st_init_driver_functions(struct dd_function_table *functions)
st_init_drawpixels_functions(functions);
st_init_rasterpos_functions(functions);
#endif
+
+#if FEATURE_OES_draw_texture
+ st_init_drawtex_functions(functions);
+#endif
+
st_init_fbo_functions(functions);
st_init_get_functions(functions);
#if FEATURE_feedback
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 3f835d38dd5..ce3c302e48e 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -183,6 +183,10 @@ void st_init_extensions(struct st_context *st)
ctx->Extensions.NV_texgen_reflection = GL_TRUE;
ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
+#if FEATURE_OES_draw_texture
+ ctx->Extensions.OES_draw_texture = GL_TRUE;
+#endif
+
ctx->Extensions.SGI_color_matrix = GL_TRUE;
ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;