From e5d2fbf3528ed96f6b0afc953232983b8753b03a Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 2 Jun 2017 16:15:52 -0700 Subject: [PATCH] meta: Stop frobbing MatrixMode text data bss dec hex filename 12243510 1344936 1290748 14879194 e309da before/lib64/dri/i965_dri.so 12243446 1344936 1290748 14879130 e3099a after/lib64/dri/i965_dri.so v2: Use _mesa_load_matrix to set the projection matrix instead of frobbing dirty bits directly. Suggested by Jason. Clean up some comments in the neighborhood. Since glOrtho isn't called, there's no point in mentioning it in the comment. Only _mesa_load_identity_matrix on the projection matrix when it isn't set to an ortho matrix. Reviewed-by: Jason Ekstrand Part-of: --- src/mesa/drivers/common/meta.c | 53 ++++++++++++++-------------------- src/mesa/drivers/common/meta.h | 1 - 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 5efe30dead2..aecc6d10b1c 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -686,31 +686,31 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state) } if (state & MESA_META_TRANSFORM) { - GLuint activeTexture = ctx->Texture.CurrentUnit; memcpy(save->ModelviewMatrix, ctx->ModelviewMatrixStack.Top->m, 16 * sizeof(GLfloat)); memcpy(save->ProjectionMatrix, ctx->ProjectionMatrixStack.Top->m, 16 * sizeof(GLfloat)); memcpy(save->TextureMatrix, ctx->TextureMatrixStack[0].Top->m, 16 * sizeof(GLfloat)); - save->MatrixMode = ctx->Transform.MatrixMode; + /* set 1:1 vertex:pixel coordinate transform */ - _mesa_ActiveTexture(GL_TEXTURE0); - _mesa_MatrixMode(GL_TEXTURE); - _mesa_LoadIdentity(); - _mesa_ActiveTexture(GL_TEXTURE0 + activeTexture); - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_LoadIdentity(); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_LoadIdentity(); - - /* glOrtho with width = 0 or height = 0 generates GL_INVALID_VALUE. - * This can occur when there is no draw buffer. + _mesa_load_identity_matrix(ctx, &ctx->ModelviewMatrixStack); + _mesa_load_identity_matrix(ctx, &ctx->TextureMatrixStack[0]); + + /* _math_float_ortho with width = 0 or height = 0 will have a divide by + * zero. This can occur when there is no draw buffer. */ - if (ctx->DrawBuffer->Width != 0 && ctx->DrawBuffer->Height != 0) - _mesa_Ortho(0.0, ctx->DrawBuffer->Width, - 0.0, ctx->DrawBuffer->Height, - -1.0, 1.0); + if (ctx->DrawBuffer->Width != 0 && ctx->DrawBuffer->Height != 0) { + float m[16]; + + _math_float_ortho(m, + 0.0f, (float) ctx->DrawBuffer->Width, + 0.0f, (float) ctx->DrawBuffer->Height, + -1.0f, 1.0f); + _mesa_load_matrix(ctx, &ctx->ProjectionMatrixStack, m); + } else { + _mesa_load_identity_matrix(ctx, &ctx->ProjectionMatrixStack); + } if (ctx->Extensions.ARB_clip_control) { save->ClipOrigin = ctx->Transform.ClipOrigin; @@ -1102,19 +1102,9 @@ _mesa_meta_end(struct gl_context *ctx) } if (state & MESA_META_TRANSFORM) { - GLuint activeTexture = ctx->Texture.CurrentUnit; - _mesa_ActiveTexture(GL_TEXTURE0); - _mesa_MatrixMode(GL_TEXTURE); - _mesa_LoadMatrixf(save->TextureMatrix); - _mesa_ActiveTexture(GL_TEXTURE0 + activeTexture); - - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_LoadMatrixf(save->ModelviewMatrix); - - _mesa_MatrixMode(GL_PROJECTION); - _mesa_LoadMatrixf(save->ProjectionMatrix); - - _mesa_MatrixMode(save->MatrixMode); + _mesa_load_matrix(ctx, &ctx->ModelviewMatrixStack, save->ModelviewMatrix); + _mesa_load_matrix(ctx, &ctx->ProjectionMatrixStack, save->ProjectionMatrix); + _mesa_load_matrix(ctx, &ctx->TextureMatrixStack[0], save->TextureMatrix); if (ctx->Extensions.ARB_clip_control) _mesa_ClipControl(save->ClipOrigin, save->ClipDepthMode); @@ -1500,8 +1490,7 @@ _mesa_meta_setup_ff_tnl_for_blit(struct gl_context *ctx, 0); /* setup projection matrix */ - _mesa_MatrixMode(GL_PROJECTION); - _mesa_LoadIdentity(); + _mesa_load_identity_matrix(ctx, &ctx->ProjectionMatrixStack); } /** diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h index 511ffb45a78..6fefbeb7880 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -133,7 +133,6 @@ struct save_state struct gl_stencil_attrib Stencil; /** MESA_META_TRANSFORM */ - GLenum MatrixMode; GLfloat ModelviewMatrix[16]; GLfloat ProjectionMatrix[16]; GLfloat TextureMatrix[16]; -- 2.30.2