*/
#include <stdbool.h>
+#include "main/arrayobj.h"
#include "main/glheader.h"
#include "main/bufferobj.h"
#include "main/context.h"
-#include "main/imports.h"
-#include "main/mtypes.h"
+#include "main/mesa_private.h"
#include "main/macros.h"
#include "main/light.h"
#include "main/state.h"
#include "vbo_private.h"
-/**
- * After playback, copy everything but the position from the
- * last vertex to the saved state
- */
static void
-playback_copy_to_current(struct gl_context *ctx,
- const struct vbo_save_vertex_list *node)
+copy_vao(struct gl_context *ctx, const struct gl_vertex_array_object *vao,
+ GLbitfield mask, GLbitfield state, int shift, fi_type **data)
{
struct vbo_context *vbo = vbo_context(ctx);
- fi_type vertex[VBO_ATTRIB_MAX * 4];
- fi_type *data;
- GLbitfield64 mask;
- if (node->current_size == 0)
- return;
+ mask &= vao->Enabled;
+ while (mask) {
+ const int i = u_bit_scan(&mask);
+ const struct gl_array_attributes *attrib = &vao->VertexAttrib[i];
+ struct gl_array_attributes *currval = &vbo->current[shift + i];
+ const GLubyte size = attrib->Format.Size;
+ const GLenum16 type = attrib->Format.Type;
+ fi_type tmp[8];
+ int dmul = 1;
+
+ if (type == GL_DOUBLE ||
+ type == GL_UNSIGNED_INT64_ARB)
+ dmul = 2;
+
+ if (dmul == 2)
+ memcpy(tmp, *data, size * dmul * sizeof(GLfloat));
+ else
+ COPY_CLEAN_4V_TYPE_AS_UNION(tmp, size, *data, type);
- if (node->current_data) {
- data = node->current_data;
- }
- else {
- /* Position of last vertex */
- const GLuint pos = node->vertex_count > 0 ? node->vertex_count - 1 : 0;
- /* Offset to last vertex in the vertex buffer */
- const GLuint offset = node->buffer_offset
- + pos * node->vertex_size * sizeof(GLfloat);
+ if (type != currval->Format.Type ||
+ memcmp(currval->Ptr, tmp, 4 * sizeof(GLfloat) * dmul) != 0) {
+ memcpy((fi_type*)currval->Ptr, tmp, 4 * sizeof(GLfloat) * dmul);
- data = vertex;
+ vbo_set_vertex_format(&currval->Format, size, type);
- ctx->Driver.GetBufferSubData(ctx, offset,
- node->vertex_size * sizeof(GLfloat),
- data, node->vertex_store->bufferobj);
+ ctx->NewState |= state;
+ }
- data += node->attrsz[0]; /* skip vertex position */
+ *data += size;
}
+}
- mask = node->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
- while (mask) {
- const int i = u_bit_scan64(&mask);
- fi_type *current = (fi_type *)vbo->currval[i].Ptr;
- fi_type tmp[4];
- assert(node->attrsz[i]);
-
- COPY_CLEAN_4V_TYPE_AS_UNION(tmp,
- node->attrsz[i],
- data,
- node->attrtype[i]);
-
- if (node->attrtype[i] != vbo->currval[i].Type ||
- memcmp(current, tmp, 4 * sizeof(GLfloat)) != 0) {
- memcpy(current, tmp, 4 * sizeof(GLfloat));
-
- vbo->currval[i].Size = node->attrsz[i];
- vbo->currval[i]._ElementSize = vbo->currval[i].Size * sizeof(GLfloat);
- vbo->currval[i].Type = node->attrtype[i];
- vbo->currval[i].Integer =
- vbo_attrtype_to_integer_flag(node->attrtype[i]);
-
- if (i >= VBO_ATTRIB_FIRST_MATERIAL &&
- i <= VBO_ATTRIB_LAST_MATERIAL)
- ctx->NewState |= _NEW_LIGHT;
-
- ctx->NewState |= _NEW_CURRENT_ATTRIB;
- }
+/**
+ * After playback, copy everything but the position from the
+ * last vertex to the saved state
+ */
+static void
+playback_copy_to_current(struct gl_context *ctx,
+ const struct vbo_save_vertex_list *node)
+{
+ if (!node->current_data)
+ return;
- data += node->attrsz[i];
- }
+ fi_type *data = node->current_data;
+ /* Copy conventional attribs and generics except pos */
+ copy_vao(ctx, node->VAO[VP_MODE_SHADER], ~VERT_BIT_POS & VERT_BIT_ALL,
+ _NEW_CURRENT_ATTRIB, 0, &data);
+ /* Copy materials */
+ copy_vao(ctx, node->VAO[VP_MODE_FF], VERT_BIT_MAT_ALL,
+ _NEW_CURRENT_ATTRIB | _NEW_LIGHT, VBO_MATERIAL_SHIFT, &data);
/* Colormaterial -- this kindof sucks.
*/
/**
- * Treat the vertex storage as a VBO, define vertex arrays pointing
- * into it:
+ * Set the appropriate VAO to draw.
*/
static void
bind_vertex_list(struct gl_context *ctx,
const struct vbo_save_vertex_list *node)
{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_save_context *save = &vbo->save;
- struct gl_vertex_array *arrays = save->arrays;
- const GLubyte *map;
- GLuint attr;
- GLbitfield varying_inputs = 0x0;
- bool generic_from_pos = false;
-
- /* Install the default (ie Current) attributes first */
- for (attr = 0; attr < VERT_ATTRIB_FF_MAX; attr++) {
- save->inputs[attr] = &vbo->currval[VBO_ATTRIB_POS + attr];
- }
-
- /* Overlay other active attributes */
- switch (get_vp_mode(ctx)) {
- case VP_FF:
- for (attr = 0; attr < VERT_ATTRIB_MAT_MAX; attr++) {
- save->inputs[VERT_ATTRIB_MAT(attr)] =
- &vbo->currval[VBO_ATTRIB_MAT_FRONT_AMBIENT+attr];
- }
- for (attr = VERT_ATTRIB_MAT_MAX; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
- save->inputs[VERT_ATTRIB_GENERIC(attr)] =
- &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
- }
- map = vbo->map_vp_none;
- break;
- case VP_SHADER:
- for (attr = 0; attr < VERT_ATTRIB_GENERIC_MAX; attr++) {
- save->inputs[VERT_ATTRIB_GENERIC(attr)] =
- &vbo->currval[VBO_ATTRIB_GENERIC0+attr];
- }
- map = vbo->map_vp_arb;
-
- /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
- * In that case we effectively need to route the data from
- * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
- */
- const GLbitfield64 inputs_read =
- ctx->VertexProgram._Current->info.inputs_read;
- if ((inputs_read & VERT_BIT_POS) == 0 &&
- (inputs_read & VERT_BIT_GENERIC0)) {
- generic_from_pos = true;
- }
- break;
- default:
- unreachable("Bad vertex program mode");
- }
-
- for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
- const GLuint src = map[attr];
- const GLubyte size = node->attrsz[src];
-
- if (size) {
- struct gl_vertex_array *array = &arrays[attr];
- const GLenum16 type = node->attrtype[src];
-
- /* override the default array set above */
- save->inputs[attr] = array;
-
- array->Ptr = (const GLubyte *) NULL + node->offsets[src];
- array->Size = size;
- array->StrideB = node->vertex_size * sizeof(GLfloat);
- array->Type = type;
- array->Integer = vbo_attrtype_to_integer_flag(type);
- array->Format = GL_RGBA;
- array->_ElementSize = size * sizeof(GLfloat);
- _mesa_reference_buffer_object(ctx,
- &array->BufferObj,
- node->vertex_store->bufferobj);
-
- assert(array->BufferObj->Name);
-
- varying_inputs |= VERT_BIT(attr);
- }
- }
-
- if (generic_from_pos) {
- varying_inputs |= (varying_inputs & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0;
- save->inputs[VERT_ATTRIB_GENERIC0] = save->inputs[VERT_ATTRIB_POS];
- }
-
- _mesa_set_varying_vp_inputs(ctx, varying_inputs);
- ctx->NewDriverState |= ctx->DriverFlags.NewArray;
+ const gl_vertex_processing_mode mode = ctx->VertexProgram._VPMode;
+ _mesa_set_draw_vao(ctx, node->VAO[mode], _vbo_get_vao_filter(mode));
}
loopback_vertex_list(struct gl_context *ctx,
const struct vbo_save_vertex_list *list)
{
- const char *buffer =
- ctx->Driver.MapBufferRange(ctx, 0,
- list->vertex_store->bufferobj->Size,
- GL_MAP_READ_BIT, /* ? */
- list->vertex_store->bufferobj,
- MAP_INTERNAL);
-
- unsigned buffer_offset =
- aligned_vertex_buffer_offset(list) ? 0 : list->buffer_offset;
-
- vbo_loopback_vertex_list(ctx,
- (const GLfloat *) (buffer + buffer_offset),
- list->attrsz,
- list->prims,
- list->prim_count,
- list->wrap_count,
- list->vertex_size);
-
- ctx->Driver.UnmapBuffer(ctx, list->vertex_store->bufferobj,
- MAP_INTERNAL);
+ struct gl_buffer_object *bo = list->VAO[0]->BufferBinding[0].BufferObj;
+ ctx->Driver.MapBufferRange(ctx, 0, bo->Size, GL_MAP_READ_BIT, /* ? */
+ bo, MAP_INTERNAL);
+
+ /* Note that the range of referenced vertices must be mapped already */
+ _vbo_loopback_vertex_list(ctx, list);
+
+ ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
}
remap_vertex_store = GL_TRUE;
}
- FLUSH_CURRENT(ctx, 0);
+ FLUSH_FOR_DRAW(ctx);
if (node->prim_count > 0) {
goto end;
}
+ bind_vertex_list(ctx, node);
+
+ /* Need that at least one time. */
if (ctx->NewState)
_mesa_update_state(ctx);
return;
}
- bind_vertex_list(ctx, node);
-
- _mesa_set_drawing_arrays(ctx, vbo->save.inputs);
-
- /* Again...
- */
- if (ctx->NewState)
- _mesa_update_state(ctx);
+ assert(ctx->NewState == 0);
if (node->vertex_count > 0) {
- GLuint min_index = node->start_vertex;
- GLuint max_index = min_index + node->vertex_count - 1;
- vbo->draw_prims(ctx,
- node->prims,
- node->prim_count,
- NULL,
- GL_TRUE,
- min_index, max_index,
- NULL, 0, NULL);
+ GLuint min_index = _vbo_save_get_min_index(node);
+ GLuint max_index = _vbo_save_get_max_index(node);
+ ctx->Driver.Draw(ctx, node->prims, node->prim_count, NULL, GL_TRUE,
+ min_index, max_index, 1, 0, NULL, 0);
}
}