Re: [Mesa-dev] [PATCH] mesa: Factor out _mesa_disable_vertex_array_attrib.
All three look good to me. Reviewed-by: Brian PaulOn 02/06/2018 12:59 AM, mathias.froehl...@gmx.net wrote: From: Mathias Fröhlich Hi, Simple code deduplication and factoring out a function that will be usefull soon. please review thanks!! Mathias And use it in the enable code path. Move _mesa_update_attribute_map_mode into its only remaining file. Signed-off-by: Mathias Fröhlich --- src/mesa/main/arrayobj.h | 26 src/mesa/main/enable.c | 64 ++-- src/mesa/main/varray.c | 58 --- src/mesa/main/varray.h | 7 ++ 4 files changed, 75 insertions(+), 80 deletions(-) diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h index 411ed65c50..5de74505bb 100644 --- a/src/mesa/main/arrayobj.h +++ b/src/mesa/main/arrayobj.h @@ -99,32 +99,6 @@ extern const GLubyte _mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX]; -/** - * Depending on the position and generic0 attributes enable flags select - * the one that is used for both attributes. - * The generic0 attribute takes precedence. - */ -static inline void -_mesa_update_attribute_map_mode(const struct gl_context *ctx, -struct gl_vertex_array_object *vao) -{ - /* -* There is no need to change the mapping away from the -* identity mapping if we are not in compat mode. -*/ - if (ctx->API != API_OPENGL_COMPAT) - return; - /* The generic0 attribute superseeds the position attribute */ - const GLbitfield enabled = vao->_Enabled; - if (enabled & VERT_BIT_GENERIC0) - vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_GENERIC0; - else if (enabled & VERT_BIT_POS) - vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_POSITION; - else - vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY; -} - - /** * Apply the position/generic0 aliasing map to a bitfield from the vao. * Use for example to convert gl_vertex_array_object::_Enabled diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index bc22410bda..967d23080c 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -40,6 +40,7 @@ #include "mtypes.h" #include "enums.h" #include "texstate.h" +#include "varray.h" @@ -58,55 +59,56 @@ update_derived_primitive_restart_state(struct gl_context *ctx) || ctx->Array.PrimitiveRestartFixedIndex; } + +/** + * Helper to enable/disable VAO client-side state. + */ +static void +vao_state(struct gl_context *ctx, gl_vert_attrib attr, GLboolean state) +{ + if (state) + _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO, attr); + else + _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attr); +} + + /** * Helper to enable/disable client-side state. */ static void client_state(struct gl_context *ctx, GLenum cap, GLboolean state) { - struct gl_vertex_array_object *vao = ctx->Array.VAO; - GLbitfield vert_attrib_bit; - GLboolean *enable_var; - switch (cap) { case GL_VERTEX_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_POS].Enabled; - vert_attrib_bit = VERT_BIT_POS; + vao_state(ctx, VERT_ATTRIB_POS, state); break; case GL_NORMAL_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_NORMAL].Enabled; - vert_attrib_bit = VERT_BIT_NORMAL; + vao_state(ctx, VERT_ATTRIB_NORMAL, state); break; case GL_COLOR_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_COLOR0].Enabled; - vert_attrib_bit = VERT_BIT_COLOR0; + vao_state(ctx, VERT_ATTRIB_COLOR0, state); break; case GL_INDEX_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled; - vert_attrib_bit = VERT_BIT_COLOR_INDEX; + vao_state(ctx, VERT_ATTRIB_COLOR_INDEX, state); break; case GL_TEXTURE_COORD_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled; - vert_attrib_bit = VERT_BIT_TEX(ctx->Array.ActiveTexture); + vao_state(ctx, VERT_ATTRIB_TEX(ctx->Array.ActiveTexture), state); break; case GL_EDGE_FLAG_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled; - vert_attrib_bit = VERT_BIT_EDGEFLAG; + vao_state(ctx, VERT_ATTRIB_EDGEFLAG, state); break; case GL_FOG_COORDINATE_ARRAY_EXT: - enable_var = >VertexAttrib[VERT_ATTRIB_FOG].Enabled; - vert_attrib_bit = VERT_BIT_FOG; + vao_state(ctx, VERT_ATTRIB_FOG, state); break; case GL_SECONDARY_COLOR_ARRAY_EXT: - enable_var = >VertexAttrib[VERT_ATTRIB_COLOR1].Enabled; - vert_attrib_bit = VERT_BIT_COLOR1; + vao_state(ctx, VERT_ATTRIB_COLOR1, state); break; case GL_POINT_SIZE_ARRAY_OES: - enable_var =
[Mesa-dev] [PATCH] mesa: Factor out _mesa_disable_vertex_array_attrib.
From: Mathias FröhlichHi, Simple code deduplication and factoring out a function that will be usefull soon. please review thanks!! Mathias And use it in the enable code path. Move _mesa_update_attribute_map_mode into its only remaining file. Signed-off-by: Mathias Fröhlich --- src/mesa/main/arrayobj.h | 26 src/mesa/main/enable.c | 64 ++-- src/mesa/main/varray.c | 58 --- src/mesa/main/varray.h | 7 ++ 4 files changed, 75 insertions(+), 80 deletions(-) diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h index 411ed65c50..5de74505bb 100644 --- a/src/mesa/main/arrayobj.h +++ b/src/mesa/main/arrayobj.h @@ -99,32 +99,6 @@ extern const GLubyte _mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX]; -/** - * Depending on the position and generic0 attributes enable flags select - * the one that is used for both attributes. - * The generic0 attribute takes precedence. - */ -static inline void -_mesa_update_attribute_map_mode(const struct gl_context *ctx, -struct gl_vertex_array_object *vao) -{ - /* -* There is no need to change the mapping away from the -* identity mapping if we are not in compat mode. -*/ - if (ctx->API != API_OPENGL_COMPAT) - return; - /* The generic0 attribute superseeds the position attribute */ - const GLbitfield enabled = vao->_Enabled; - if (enabled & VERT_BIT_GENERIC0) - vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_GENERIC0; - else if (enabled & VERT_BIT_POS) - vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_POSITION; - else - vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY; -} - - /** * Apply the position/generic0 aliasing map to a bitfield from the vao. * Use for example to convert gl_vertex_array_object::_Enabled diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index bc22410bda..967d23080c 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -40,6 +40,7 @@ #include "mtypes.h" #include "enums.h" #include "texstate.h" +#include "varray.h" @@ -58,55 +59,56 @@ update_derived_primitive_restart_state(struct gl_context *ctx) || ctx->Array.PrimitiveRestartFixedIndex; } + +/** + * Helper to enable/disable VAO client-side state. + */ +static void +vao_state(struct gl_context *ctx, gl_vert_attrib attr, GLboolean state) +{ + if (state) + _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO, attr); + else + _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attr); +} + + /** * Helper to enable/disable client-side state. */ static void client_state(struct gl_context *ctx, GLenum cap, GLboolean state) { - struct gl_vertex_array_object *vao = ctx->Array.VAO; - GLbitfield vert_attrib_bit; - GLboolean *enable_var; - switch (cap) { case GL_VERTEX_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_POS].Enabled; - vert_attrib_bit = VERT_BIT_POS; + vao_state(ctx, VERT_ATTRIB_POS, state); break; case GL_NORMAL_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_NORMAL].Enabled; - vert_attrib_bit = VERT_BIT_NORMAL; + vao_state(ctx, VERT_ATTRIB_NORMAL, state); break; case GL_COLOR_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_COLOR0].Enabled; - vert_attrib_bit = VERT_BIT_COLOR0; + vao_state(ctx, VERT_ATTRIB_COLOR0, state); break; case GL_INDEX_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled; - vert_attrib_bit = VERT_BIT_COLOR_INDEX; + vao_state(ctx, VERT_ATTRIB_COLOR_INDEX, state); break; case GL_TEXTURE_COORD_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled; - vert_attrib_bit = VERT_BIT_TEX(ctx->Array.ActiveTexture); + vao_state(ctx, VERT_ATTRIB_TEX(ctx->Array.ActiveTexture), state); break; case GL_EDGE_FLAG_ARRAY: - enable_var = >VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled; - vert_attrib_bit = VERT_BIT_EDGEFLAG; + vao_state(ctx, VERT_ATTRIB_EDGEFLAG, state); break; case GL_FOG_COORDINATE_ARRAY_EXT: - enable_var = >VertexAttrib[VERT_ATTRIB_FOG].Enabled; - vert_attrib_bit = VERT_BIT_FOG; + vao_state(ctx, VERT_ATTRIB_FOG, state); break; case GL_SECONDARY_COLOR_ARRAY_EXT: - enable_var = >VertexAttrib[VERT_ATTRIB_COLOR1].Enabled; - vert_attrib_bit = VERT_BIT_COLOR1; + vao_state(ctx, VERT_ATTRIB_COLOR1, state); break; case GL_POINT_SIZE_ARRAY_OES: - enable_var = >VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled; - vert_attrib_bit = VERT_BIT_POINT_SIZE; FLUSH_VERTICES(ctx, _NEW_PROGRAM); ctx->VertexProgram.PointSizeEnabled =