diff options
author | Chia-I Wu <olvaffe@gmail.com> | 2010-10-12 14:26:52 -0400 |
---|---|---|
committer | Chia-I Wu <olvaffe@gmail.com> | 2011-03-16 14:17:52 +0800 |
commit | d5d833a353c6be84e1a993de8725f3117afbd1f6 (patch) | |
tree | b430a7a3ff28262c63aeb7422648e4bb8486bc6c /src/mesa/drivers | |
parent | 32197c0094103d6bb06f992049306daf227f5c8e (diff) |
i915c: Add GL_OES_draw_texture support.
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r-- | src/mesa/drivers/common/meta.c | 143 | ||||
-rw-r--r-- | src/mesa/drivers/common/meta.h | 3 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_context.c | 1 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_extensions.h | 3 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_extensions_es2.c | 14 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_tex.c | 2 |
6 files changed, 166 insertions, 0 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 2b00e8979d..f71aac5e54 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -269,6 +269,16 @@ struct gen_mipmap_state #define MAX_META_OPS_DEPTH 2 /** + * State for glDrawTex() + */ +struct drawtex_state +{ + GLuint ArrayObj; + GLuint VBO; +}; + + +/** * All per-context meta state. */ struct gl_meta_state @@ -286,6 +296,7 @@ struct gl_meta_state struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */ struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */ struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */ + struct drawtex_state DrawTex; /**< For _mesa_meta_DrawTex() */ }; @@ -2850,3 +2861,135 @@ _mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start free(buf); } + + +#if FEATURE_OES_draw_texture + + +/** + * Meta implementation of ctx->Driver.DrawTex() in terms + * of polygon rendering. + */ +void +_mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z, + GLfloat width, GLfloat height) +{ + struct drawtex_state *drawtex = &ctx->Meta->DrawTex; + struct vertex { + GLfloat x, y, z, st[MAX_TEXTURE_UNITS][2]; + }; + struct vertex verts[4]; + GLuint i; + + _mesa_meta_begin(ctx, (META_RASTERIZATION | + META_SHADER | + META_TRANSFORM | + META_VERTEX | + META_VIEWPORT)); + + if (drawtex->ArrayObj == 0) { + /* one-time setup */ + GLint active_texture; + + /* create vertex array object */ + _mesa_GenVertexArrays(1, &drawtex->ArrayObj); + _mesa_BindVertexArray(drawtex->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &drawtex->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, drawtex->VBO); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + NULL, GL_DYNAMIC_DRAW_ARB); + + /* client active texture is not part of the array object */ + active_texture = ctx->Array.ActiveTexture; + + /* setup vertex arrays */ + _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { + _mesa_ClientActiveTextureARB(GL_TEXTURE0 + i); + _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(st[i])); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + } + + /* restore client active texture */ + _mesa_ClientActiveTextureARB(GL_TEXTURE0 + active_texture); + } + else { + _mesa_BindVertexArray(drawtex->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, drawtex->VBO); + } + + /* vertex positions, texcoords */ + { + const GLfloat x1 = x + width; + const GLfloat y1 = y + height; + + z = CLAMP(z, 0.0, 1.0); + z = invert_z(z); + + verts[0].x = x; + verts[0].y = y; + verts[0].z = z; + + verts[1].x = x1; + verts[1].y = y; + verts[1].z = z; + + verts[2].x = x1; + verts[2].y = y1; + verts[2].z = z; + + verts[3].x = x; + verts[3].y = y1; + verts[3].z = z; + + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { + const struct gl_texture_object *texObj; + const struct gl_texture_image *texImage; + GLfloat s, t, s1, t1; + GLuint tw, th; + + if (!ctx->Texture.Unit[i]._ReallyEnabled) { + GLuint j; + for (j = 0; j < 4; j++) { + verts[j].st[i][0] = 0.0f; + verts[j].st[i][1] = 0.0f; + } + continue; + } + + texObj = ctx->Texture.Unit[i]._Current; + texImage = texObj->Image[0][texObj->BaseLevel]; + tw = texImage->Width2; + th = texImage->Height2; + + s = (GLfloat) texObj->CropRect[0] / tw; + t = (GLfloat) texObj->CropRect[1] / th; + s1 = (GLfloat) (texObj->CropRect[0] + texObj->CropRect[2]) / tw; + t1 = (GLfloat) (texObj->CropRect[1] + texObj->CropRect[3]) / th; + + verts[0].st[i][0] = s; + verts[0].st[i][1] = t; + + verts[1].st[i][0] = s1; + verts[1].st[i][1] = t; + + verts[2].st[i][0] = s1; + verts[2].st[i][1] = t1; + + verts[3].st[i][0] = s; + verts[3].st[i][1] = t1; + } + + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + } + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + _mesa_meta_end(ctx); +} + + +#endif /* FEATURE_OES_draw_texture */ diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h index b0797d3d91..889606186b 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -114,5 +114,8 @@ _mesa_meta_CopyConvolutionFilter2D(struct gl_context *ctx, GLenum target, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height); +extern void +_mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z, + GLfloat width, GLfloat height); #endif /* META_H */ diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index c2e2a98af5..a5334f8367 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -851,6 +851,7 @@ intelInitContext(struct intel_context *intel, intelInitExtensions(ctx); break; case API_OPENGLES: + intelInitExtensionsES1(ctx); break; case API_OPENGLES2: intelInitExtensionsES2(ctx); diff --git a/src/mesa/drivers/dri/intel/intel_extensions.h b/src/mesa/drivers/dri/intel/intel_extensions.h index fb2a846d39..9991c00010 100644 --- a/src/mesa/drivers/dri/intel/intel_extensions.h +++ b/src/mesa/drivers/dri/intel/intel_extensions.h @@ -33,6 +33,9 @@ extern void intelInitExtensions(struct gl_context *ctx); extern void +intelInitExtensionsES1(struct gl_context *ctx); + +extern void intelInitExtensionsES2(struct gl_context *ctx); diff --git a/src/mesa/drivers/dri/intel/intel_extensions_es2.c b/src/mesa/drivers/dri/intel/intel_extensions_es2.c index 5ef6b0561d..ef7f2c968e 100644 --- a/src/mesa/drivers/dri/intel/intel_extensions_es2.c +++ b/src/mesa/drivers/dri/intel/intel_extensions_es2.c @@ -80,6 +80,20 @@ static const char *es2_extensions[] = { NULL, }; +void +intelInitExtensionsES1(struct gl_context *ctx) +{ + int i; + + /* Can't use driInitExtensions() since it uses extensions from + * main/remap_helper.h when called the first time. */ + + for (i = 0; es2_extensions[i]; i++) + _mesa_enable_extension(ctx, es2_extensions[i]); + + _mesa_enable_extension(ctx, "GL_OES_draw_texture"); +} + /** * \brief Extensions to disable. * diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c index 2c3eab20fd..077c611901 100644 --- a/src/mesa/drivers/dri/intel/intel_tex.c +++ b/src/mesa/drivers/dri/intel/intel_tex.c @@ -119,4 +119,6 @@ intelInitTextureFuncs(struct dd_function_table *functions) functions->NewTextureImage = intelNewTextureImage; functions->DeleteTexture = intelDeleteTextureObject; functions->FreeTexImageData = intelFreeTextureImageData; + + functions->DrawTex = _mesa_meta_DrawTex; } |