#include "glheader.h"
#include "context.h"
#include "imports.h"
#include "mtypes.h"
#include "macros.h"
#include "light.h"
#include "state.h"
#include "vbo_context.h"
static void _playback_copy_to_current( GLcontext *ctx,
const struct vbo_save_vertex_list *node )
{
struct vbo_context *vbo = vbo_context(ctx);
GLfloat vertex[VBO_ATTRIB_MAX * 4], *data = vertex;
GLuint i, offset;
if (node->count)
offset = (node->buffer_offset +
(node->count-1) * node->vertex_size * sizeof(GLfloat));
else
offset = node->buffer_offset;
ctx->Driver.GetBufferSubData( ctx, 0, offset,
node->vertex_size * sizeof(GLfloat),
data, node->vertex_store->bufferobj );
data += node->attrsz[0];
for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
if (node->attrsz[i]) {
GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
COPY_CLEAN_4V(current,
node->attrsz[i],
data);
vbo->currval[i].Size = node->attrsz[i];
data += node->attrsz[i];
if (i >= VBO_ATTRIB_FIRST_MATERIAL &&
i <= VBO_ATTRIB_LAST_MATERIAL)
ctx->NewState |= _NEW_LIGHT;
}
}
if (ctx->Light.ColorMaterialEnabled) {
_mesa_update_color_material(ctx, ctx->Current.Attrib[VBO_ATTRIB_COLOR0]);
}
if (node->prim_count) {
const struct _mesa_prim *prim = &node->prim[node->prim_count - 1];
if (prim->end)
ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
else
ctx->Driver.CurrentExecPrimitive = prim->mode;
}
}
static void vbo_bind_vertex_list( GLcontext *ctx,
const struct vbo_save_vertex_list *node )
{
struct vbo_context *vbo = vbo_context(ctx);
struct vbo_save_context *save = &vbo->save;
struct gl_client_array *arrays = save->arrays;
GLuint data = node->buffer_offset;
const GLuint *map;
GLuint attr;
switch (get_program_mode(ctx)) {
case VP_NONE:
memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
memcpy(arrays + 16, vbo->mat_currval, MAT_ATTRIB_MAX * sizeof(arrays[0]));
map = vbo->map_vp_none;
break;
case VP_NV:
case VP_ARB:
memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
map = vbo->map_vp_arb;
break;
}
for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
GLuint src = map[attr];
if (node->attrsz[src]) {
arrays[attr].Ptr = (const GLubyte *)data;
arrays[attr].Size = node->attrsz[src];
arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
arrays[attr].Stride = node->vertex_size * sizeof(GLfloat);
arrays[attr].Type = GL_FLOAT;
arrays[attr].Enabled = 1;
arrays[attr].BufferObj = node->vertex_store->bufferobj;
arrays[attr]._MaxElement = node->count;
assert(arrays[attr].BufferObj->Name);
data += node->attrsz[src] * sizeof(GLfloat);
}
}
}
static void vbo_save_loopback_vertex_list( GLcontext *ctx,
const struct vbo_save_vertex_list *list )
{
const char *buffer = ctx->Driver.MapBuffer(ctx,
GL_ARRAY_BUFFER_ARB,
GL_READ_ONLY,
list->vertex_store->bufferobj);
vbo_loopback_vertex_list( ctx,
(const GLfloat *)(buffer + list->buffer_offset),
list->attrsz,
list->prim,
list->prim_count,
list->wrap_count,
list->vertex_size);
ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
list->vertex_store->bufferobj);
}
void vbo_save_playback_vertex_list( GLcontext *ctx, void *data )
{
const struct vbo_save_vertex_list *node = (const struct vbo_save_vertex_list *) data;
struct vbo_save_context *save = &vbo_context(ctx)->save;
FLUSH_CURRENT(ctx, 0);
if (node->prim_count > 0 && node->count > 0) {
if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END &&
node->prim[0].begin) {
if (0)
_mesa_printf("displaylist recursive begin");
vbo_save_loopback_vertex_list( ctx, node );
return;
}
else if (save->replay_flags) {
vbo_save_loopback_vertex_list( ctx, node );
return;
}
if (ctx->NewState)
_mesa_update_state( ctx );
if ((ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) ||
(ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBegin (invalid vertex/fragment program)");
return;
}
vbo_bind_vertex_list( ctx, node );
vbo_context(ctx)->draw_prims( ctx,
save->inputs,
node->prim,
node->prim_count,
NULL,
0,
node->count - 1);
}
_playback_copy_to_current( ctx, node );
}