summaryrefslogtreecommitdiffstats
path: root/src/mesa/vbo/vbo_exec.c
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2018-02-03 17:19:24 +0100
committerMathias Fröhlich <[email protected]>2018-02-23 05:33:46 +0100
commit6002ab564bfb643d5e9fd1b8c3c7c45384de570a (patch)
tree2b85efeeb9378b6f3b798733bca9cec121eab987 /src/mesa/vbo/vbo_exec.c
parent08c7474189da25729e4e0bc8755b676e13c2c2c8 (diff)
vbo: Implement method to track the inputs array.
Provided the _DrawVAO and the derived state that is maintained if we have the _DrawVAO set, implement a method to incrementally update the array of gl_vertex_array input pointers. v2: Add some more comments. Rename _vbo_array_init to _vbo_init_inputs. Rename vbo_context::arrays to vbo_context::draw_arrays. Signed-off-by: Mathias Fröhlich <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/vbo/vbo_exec.c')
-rw-r--r--src/mesa/vbo/vbo_exec.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/mesa/vbo/vbo_exec.c b/src/mesa/vbo/vbo_exec.c
index 372d0237aad..69a150c78b7 100644
--- a/src/mesa/vbo/vbo_exec.c
+++ b/src/mesa/vbo/vbo_exec.c
@@ -27,6 +27,7 @@
#include "main/glheader.h"
+#include "main/arrayobj.h"
#include "main/mtypes.h"
#include "main/api_arrayelt.h"
#include "main/vtxfmt.h"
@@ -240,3 +241,85 @@ vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1)
p0->count += p1->count;
p0->end = p1->end;
}
+
+
+void
+_vbo_init_inputs(struct vbo_inputs *inputs)
+{
+ inputs->current = 0;
+ inputs->vertex_processing_mode = VP_MODE_FF;
+}
+
+
+/**
+ * Update the vbo_inputs's arrays to point to the vao->_VertexArray arrays
+ * according to the 'enable' bitmask.
+ * \param enable bitfield of VERT_BIT_x flags.
+ */
+static inline void
+update_vao_inputs(struct gl_context *ctx,
+ struct vbo_inputs *inputs, GLbitfield enable)
+{
+ const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO;
+
+ /* Make sure we process only arrays enabled in the VAO */
+ assert((enable & ~_mesa_get_vao_vp_inputs(vao)) == 0);
+
+ /* Fill in the client arrays from the VAO */
+ const GLubyte *const map = _mesa_vao_attribute_map[vao->_AttributeMapMode];
+ const struct gl_vertex_array *array = vao->_VertexArray;
+ const struct gl_vertex_array **iarray = &inputs->inputs[0];
+ while (enable) {
+ const int attr = u_bit_scan(&enable);
+ iarray[attr] = &array[map[attr]];
+ }
+}
+
+
+/**
+ * Update the vbo_inputs's arrays to point to the vbo->currval arrays
+ * according to the 'current' bitmask.
+ * \param current bitfield of VERT_BIT_x flags.
+ */
+static inline void
+update_current_inputs(struct gl_context *ctx,
+ struct vbo_inputs *inputs, GLbitfield current)
+{
+ gl_vertex_processing_mode mode = ctx->VertexProgram._VPMode;
+
+ /* All previously non current array pointers need update. */
+ GLbitfield mask = current & ~inputs->current;
+ /* On mode change, the slots aliasing with materials need update too */
+ if (mode != inputs->vertex_processing_mode)
+ mask |= current & VERT_BIT_MAT_ALL;
+
+ struct vbo_context *vbo = vbo_context(ctx);
+ const struct gl_vertex_array *const currval = &vbo->currval[0];
+ const struct gl_vertex_array **iarray = &inputs->inputs[0];
+ const GLubyte *const map = _vbo_attribute_alias_map[mode];
+ while (mask) {
+ const int attr = u_bit_scan(&mask);
+ iarray[attr] = &currval[map[attr]];
+ }
+
+ inputs->current = current;
+ inputs->vertex_processing_mode = mode;
+}
+
+
+/**
+ * Update the vbo_inputs's arrays to point to the vao->_VertexArray and
+ * vbo->currval arrays according to Array._DrawVAO and
+ * Array._DrawVAOEnableAttribs.
+ */
+void
+_vbo_update_inputs(struct gl_context *ctx, struct vbo_inputs *inputs)
+{
+ const GLbitfield enable = ctx->Array._DrawVAOEnabledAttribs;
+
+ /* Update array input pointers */
+ update_vao_inputs(ctx, inputs, enable);
+
+ /* The rest must be current inputs. */
+ update_current_inputs(ctx, inputs, ~enable & VERT_BIT_ALL);
+}