From b4fd63015ac7fd73e0147ff078caec47be729e87 Mon Sep 17 00:00:00 2001 From: Mathias Fröhlich Date: Sat, 27 Jan 2018 16:07:22 +0100 Subject: mesa: Track position/generic0 aliasing in the VAO. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the first material attribute no longer aliases with the generic0 attribute, only aliasing between generic0 and position is left and entirely dependent on the enabled state of the VAO. So introduce a gl_attribute_map_mode in the VAO that is used to track how the position and the generic 0 attribute alias. Provide a static const array that can be used to map from vertex program input indices to VERT_ATTRIB_* indices. The outer dimension of the array is meant to be indexed directly by the new VAO member variable. Also provide methods on the VAO to convert bitmasks of VERT_BIT's from the VAO numbering to the vertex processing inputs numbering. v2: s,unsigned char,GLubyte,g s,_ATTRIBUTE_MAP_MODE_MAX,ATTRIBUTE_MAP_MODE_MAX,g Change comment style, add comments. Signed-off-by: Mathias Fröhlich Reviewed-by: Brian Paul --- src/mesa/main/arrayobj.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/mesa/main/arrayobj.h') diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h index ff26157c79e..411ed65c50b 100644 --- a/src/mesa/main/arrayobj.h +++ b/src/mesa/main/arrayobj.h @@ -89,6 +89,80 @@ _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao); extern bool _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao); + +/** + * Array to apply the position/generic0 aliasing map to + * an attribute value used in vertex processing inputs to an attribute + * as they appear in the vao. + */ +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 + * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to + * the numbering used with vertex processing inputs. + */ +static inline GLbitfield +_mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled) +{ + switch (mode) { + case ATTRIBUTE_MAP_MODE_IDENTITY: + return enabled; + case ATTRIBUTE_MAP_MODE_POSITION: + /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */ + return (enabled & ~VERT_BIT_GENERIC0) + | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0); + case ATTRIBUTE_MAP_MODE_GENERIC0: + /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */ + return (enabled & ~VERT_BIT_POS) + | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0); + default: + return 0; + } +} + + +/** + * Return the vp_inputs enabled bitmask after application of + * the position/generic0 aliasing map. + */ +static inline GLbitfield +_mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao) +{ + const gl_attribute_map_mode mode = vao->_AttributeMapMode; + return _mesa_vao_enable_to_vp_inputs(mode, vao->_Enabled); +} + + /* * API functions */ -- cgit v1.2.3