diff options
author | Pierre-Eric Pelloux-Prayer <[email protected]> | 2019-05-07 11:20:20 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-06-03 15:28:49 -0400 |
commit | 28ce704bb012e0510bfb90659020764800e62e82 (patch) | |
tree | 095c8a2156030e7f1707255963cef4d0385e81c6 /src/mesa/main/matrix.c | |
parent | b69584ad6983b7e2d025ea1cc4ace78c1e46002f (diff) |
mesa: factor out enum -> matrix stack lookup
Split this out from glMatrixMode since we're about to need it
independently for EXT_DSA.
Adapted from Chris Forbes commit.
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/main/matrix.c')
-rw-r--r-- | src/mesa/main/matrix.c | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index 8065a83705c..3b5159e1c7e 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -46,6 +46,54 @@ #include "util/bitscan.h" +static struct gl_matrix_stack * +get_named_matrix_stack(struct gl_context *ctx, GLenum mode) +{ + switch (mode) { + case GL_MODELVIEW: + return &ctx->ModelviewMatrixStack; + case GL_PROJECTION: + return &ctx->ProjectionMatrixStack; + case GL_TEXTURE: + /* This error check is disabled because if we're called from + * glPopAttrib() when the active texture unit is >= MaxTextureCoordUnits + * we'll generate an unexpected error. + * From the GL_ARB_vertex_shader spec it sounds like we should instead + * do error checking in other places when we actually try to access + * texture matrices beyond MaxTextureCoordUnits. + */ +#if 0 + if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glMatrixMode(invalid tex unit %d)", + ctx->Texture.CurrentUnit); + return; + } +#endif + assert(ctx->Texture.CurrentUnit < ARRAY_SIZE(ctx->TextureMatrixStack)); + return &ctx->TextureMatrixStack[ctx->Texture.CurrentUnit]; + case GL_MATRIX0_ARB: + case GL_MATRIX1_ARB: + case GL_MATRIX2_ARB: + case GL_MATRIX3_ARB: + case GL_MATRIX4_ARB: + case GL_MATRIX5_ARB: + case GL_MATRIX6_ARB: + case GL_MATRIX7_ARB: + if (ctx->API == API_OPENGL_COMPAT + && (ctx->Extensions.ARB_vertex_program || + ctx->Extensions.ARB_fragment_program)) { + const GLuint m = mode - GL_MATRIX0_ARB; + if (m <= ctx->Const.MaxProgramMatrices) + return &ctx->ProgramMatrixStack[m]; + } + /* fallthrough */ + default: + return NULL; + } +} + + /** * Apply a perspective projection matrix. * @@ -148,67 +196,21 @@ _mesa_Ortho( GLdouble left, GLdouble right, void GLAPIENTRY _mesa_MatrixMode( GLenum mode ) { + struct gl_matrix_stack * stack; GET_CURRENT_CONTEXT(ctx); if (ctx->Transform.MatrixMode == mode && mode != GL_TEXTURE) return; - switch (mode) { - case GL_MODELVIEW: - ctx->CurrentStack = &ctx->ModelviewMatrixStack; - break; - case GL_PROJECTION: - ctx->CurrentStack = &ctx->ProjectionMatrixStack; - break; - case GL_TEXTURE: - /* This error check is disabled because if we're called from - * glPopAttrib() when the active texture unit is >= MaxTextureCoordUnits - * we'll generate an unexpected error. - * From the GL_ARB_vertex_shader spec it sounds like we should instead - * do error checking in other places when we actually try to access - * texture matrices beyond MaxTextureCoordUnits. - */ -#if 0 - if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glMatrixMode(invalid tex unit %d)", - ctx->Texture.CurrentUnit); - return; - } -#endif - assert(ctx->Texture.CurrentUnit < ARRAY_SIZE(ctx->TextureMatrixStack)); - ctx->CurrentStack = &ctx->TextureMatrixStack[ctx->Texture.CurrentUnit]; - break; - case GL_MATRIX0_ARB: - case GL_MATRIX1_ARB: - case GL_MATRIX2_ARB: - case GL_MATRIX3_ARB: - case GL_MATRIX4_ARB: - case GL_MATRIX5_ARB: - case GL_MATRIX6_ARB: - case GL_MATRIX7_ARB: - if (ctx->API == API_OPENGL_COMPAT - && (ctx->Extensions.ARB_vertex_program || - ctx->Extensions.ARB_fragment_program)) { - const GLuint m = mode - GL_MATRIX0_ARB; - if (m > ctx->Const.MaxProgramMatrices) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glMatrixMode(GL_MATRIX%d_ARB)", m); - return; - } - ctx->CurrentStack = &ctx->ProgramMatrixStack[m]; - } - else { - _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" ); - return; - } - break; - default: + stack = get_named_matrix_stack(ctx, mode); + + if (stack) { + ctx->CurrentStack = stack; + ctx->Transform.MatrixMode = mode; + } + else { _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" ); - return; } - - ctx->Transform.MatrixMode = mode; } |