From dea3bc04c195582b347c3eeab9ac952ba7564017 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 15 Sep 2009 15:22:18 +0800 Subject: mesa/tnl: Add support for GL_FIXED in _tnl_import_array. --- src/mesa/tnl/t_draw.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c index 04fa106300..978a303f59 100644 --- a/src/mesa/tnl/t_draw.c +++ b/src/mesa/tnl/t_draw.c @@ -158,6 +158,18 @@ static void _tnl_import_array( GLcontext *ctx, case GL_DOUBLE: CONVERT(GLdouble, (GLfloat)); break; +#if FEATURE_fixedpt + case GL_FIXED: + { + GLuint i, j; + for (i = 0; i < count; i++) { + const GLint *in = (GLint *) (ptr + i * input->StrideB); + for (j = 0; j < sz; j++) + *fptr++ = *in++ / 65536.0f; + } + } + break; +#endif default: assert(0); break; -- cgit v1.2.3 From d535d82b325a23a21ab01d9279db67a853245624 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 15 Sep 2009 17:47:13 +0800 Subject: mesa: Add _mesa_meta_draw_tex. --- src/mesa/drivers/common/meta.c | 141 +++++++++++++++++++++++++++++++++++++++++ src/mesa/drivers/common/meta.h | 3 + 2 files changed, 144 insertions(+) diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 05909cfa30..aff25ce800 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -228,6 +228,16 @@ struct gen_mipmap_state }; +/** + * State for glDrawTex() + */ +struct drawtex_state +{ + GLuint ArrayObj; + GLuint VBO; +}; + + /** * All per-context meta state. */ @@ -243,6 +253,8 @@ struct gl_meta_state struct drawpix_state DrawPix; /**< For _mesa_meta_draw_pixels() */ struct bitmap_state Bitmap; /**< For _mesa_meta_bitmap() */ struct gen_mipmap_state Mipmap; /**< For _mesa_meta_generate_mipmap() */ + + struct drawtex_state DrawTex; /**< For _mesa_meta_draw_tex() */ }; @@ -299,6 +311,11 @@ _mesa_meta_free(GLcontext *ctx) _mesa_DeleteBuffersARB(1, & meta->Bitmap.VBO); _mesa_DeleteVertexArraysAPPLE(1, &meta->Bitmap.ArrayObj); _mesa_DeleteTextures(1, &meta->Bitmap.Tex.TexObj); + + /* glDrawTex */ + _mesa_DeleteBuffersARB(1, & meta->DrawTex.VBO); + _mesa_DeleteVertexArraysAPPLE(1, &meta->DrawTex.ArrayObj); + } _mesa_free(ctx->Meta); @@ -2037,3 +2054,127 @@ _mesa_meta_generate_mipmap(GLcontext *ctx, GLenum target, /* restore (XXX add to meta_begin/end()? */ _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave); } + + +#if FEATURE_OES_draw_texture + + +/** + * Meta implementation of ctx->Driver.DrawTex() in terms + * of texture mapping and polygon rendering. + */ +void +_mesa_meta_draw_tex(GLcontext *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]; + GLboolean vp_enabled; + GLuint i; + + _mesa_meta_begin(ctx, (META_RASTERIZATION | + META_TRANSFORM | + META_VERTEX | + META_VIEWPORT)); + vp_enabled = ctx->VertexProgram.Enabled; + if (vp_enabled) + _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_FALSE); + + if (drawtex->ArrayObj == 0) { + /* one-time setup */ + + /* 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); + + /* 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); + } + } + else { + _mesa_BindVertexArray(drawtex->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, drawtex->VBO); + } + + /* vertex positions, texcoords */ + { + const GLfloat x1 = x + width * ctx->Pixel.ZoomX; + const GLfloat y1 = y + height * ctx->Pixel.ZoomY; + + 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; + + 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]; + + s = texObj->CropRect[0] / texImage->Width2; + t = texObj->CropRect[1] / texImage->Height2; + s1 = (texObj->CropRect[0] + texObj->CropRect[2]) / texImage->Width2; + t1 = (texObj->CropRect[1] + texObj->CropRect[3]) / texImage->Height2; + + 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); + + if (vp_enabled) + _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_TRUE); + _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 171ad27f26..82d8b67af0 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -87,5 +87,8 @@ extern void _mesa_meta_generate_mipmap(GLcontext *ctx, GLenum target, struct gl_texture_object *texObj); +extern void +_mesa_meta_draw_tex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, + GLfloat width, GLfloat height); #endif /* META_H */ -- cgit v1.2.3 From 4e547d5155d1943576cc6127e537f78fdb7c6ab7 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 15 Sep 2009 17:51:25 +0800 Subject: intel: Add support for GL_OES_draw_texture. --- src/mesa/drivers/dri/intel/intel_context.c | 3 +++ src/mesa/drivers/dri/intel/intel_extensions.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index 7a2e7617d0..fb7409c07e 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -604,6 +604,9 @@ intelInitDriverFunctions(struct dd_function_table *functions) intelInitBufferObjectFuncs(functions); intel_init_syncobj_functions(functions); +#if FEATURE_OES_draw_texture + functions->DrawTex = _mesa_meta_draw_tex; +#endif intelInitEGLImageFuncs(functions); } diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c index 21af22fbfb..3d01e2e028 100644 --- a/src/mesa/drivers/dri/intel/intel_extensions.c +++ b/src/mesa/drivers/dri/intel/intel_extensions.c @@ -181,6 +181,9 @@ static const struct dri_extension ttm_extensions[] = { { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions }, #if FEATURE_OES_EGL_image { "GL_OES_EGL_image", NULL }, +#endif +#if FEATURE_OES_draw_texture + { "GL_OES_draw_texture", NULL }, #endif { NULL, NULL } }; -- cgit v1.2.3 From 705fed33eaf60341b6ebc7c0d202dab3f18543a8 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 15 Sep 2009 18:40:24 +0800 Subject: mesa: Fix a division in _mesa_meta_draw_tex. Both crop rectangle and texture dimensions are integers. Cast to get float division. --- src/mesa/drivers/common/meta.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index aff25ce800..5c794ee443 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -2135,6 +2135,7 @@ _mesa_meta_draw_tex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, 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; @@ -2147,11 +2148,13 @@ _mesa_meta_draw_tex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, texObj = ctx->Texture.Unit[i]._Current; texImage = texObj->Image[0][texObj->BaseLevel]; + tw = texImage->Width2; + th = texImage->Height2; - s = texObj->CropRect[0] / texImage->Width2; - t = texObj->CropRect[1] / texImage->Height2; - s1 = (texObj->CropRect[0] + texObj->CropRect[2]) / texImage->Width2; - t1 = (texObj->CropRect[1] + texObj->CropRect[3]) / 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; -- cgit v1.2.3