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 <Mathias.Froehlich@web.de>
Reviewed-by: Brian Paul <brianp@vmware.com>
/**
- * 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
#include "mtypes.h"
#include "enums.h"
#include "texstate.h"
+#include "varray.h"
|| 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 = &vao->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 = &vao->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 = &vao->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 = &vao->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 = &vao->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 = &vao->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 = &vao->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 = &vao->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 = &vao->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
- vert_attrib_bit = VERT_BIT_POINT_SIZE;
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
ctx->VertexProgram.PointSizeEnabled = state;
+ vao_state(ctx, VERT_ATTRIB_POINT_SIZE, state);
break;
/* GL_NV_primitive_restart */
goto invalid_enum_error;
}
- if (*enable_var == state)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_ARRAY);
-
- *enable_var = state;
-
- if (state)
- vao->_Enabled |= vert_attrib_bit;
- else
- vao->_Enabled &= ~vert_attrib_bit;
-
- vao->NewArrays |= vert_attrib_bit;
-
- /* Something got en/disabled, so update the map mode */
- if (vert_attrib_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
- _mesa_update_attribute_map_mode(ctx, vao);
-
if (ctx->Driver.Enable) {
ctx->Driver.Enable( ctx, cap, state );
}
/**
+ * 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
+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;
+}
+
+
+/**
* Sets the BufferBindingIndex field for the vertex attribute given by
* attribIndex.
*/
/* Update the map mode if needed */
if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
- _mesa_update_attribute_map_mode(ctx, vao);
+ update_attribute_map_mode(ctx, vao);
}
}
}
-static void
-disable_vertex_array_attrib(struct gl_context *ctx,
- struct gl_vertex_array_object *vao,
- GLuint index)
+void
+_mesa_disable_vertex_array_attrib(struct gl_context *ctx,
+ struct gl_vertex_array_object *vao,
+ gl_vert_attrib attrib)
{
- assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
+ assert(attrib < ARRAY_SIZE(vao->VertexAttrib));
- if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
+ if (vao->VertexAttrib[attrib].Enabled) {
/* was enabled, now being disabled */
FLUSH_VERTICES(ctx, _NEW_ARRAY);
- vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
- const GLbitfield array_bit = VERT_BIT_GENERIC(index);
+ vao->VertexAttrib[attrib].Enabled = GL_FALSE;
+ const GLbitfield array_bit = VERT_BIT(attrib);
vao->_Enabled &= ~array_bit;
vao->NewArrays |= array_bit;
/* Update the map mode if needed */
if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
- _mesa_update_attribute_map_mode(ctx, vao);
+ update_attribute_map_mode(ctx, vao);
}
}
return;
}
- disable_vertex_array_attrib(ctx, ctx->Array.VAO, index);
+ const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
+ _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
}
_mesa_DisableVertexAttribArray_no_error(GLuint index)
{
GET_CURRENT_CONTEXT(ctx);
- disable_vertex_array_attrib(ctx, ctx->Array.VAO, index);
+ const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
+ _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
}
return;
}
- disable_vertex_array_attrib(ctx, vao, index);
+ const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
+ _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
}
{
GET_CURRENT_CONTEXT(ctx);
struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
- disable_vertex_array_attrib(ctx, vao, index);
+ const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
+ _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
}
struct gl_vertex_array_object *vao,
gl_vert_attrib attrib);
+
+extern void
+_mesa_disable_vertex_array_attrib(struct gl_context *ctx,
+ struct gl_vertex_array_object *vao,
+ gl_vert_attrib attrib);
+
+
extern void
_mesa_bind_vertex_buffer(struct gl_context *ctx,
struct gl_vertex_array_object *vao,