-static void eval_points1( GLfloat outcoord[][4],
- GLfloat coord[][4],
- const GLuint *flags,
- GLuint start,
- GLfloat du, GLfloat u1 )
-{
- GLuint i;
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & VERT_EVAL_P1)
- outcoord[i][0] = coord[i][0] * du + u1;
- else if (flags[i] & VERT_EVAL_ANY) {
- outcoord[i][0] = coord[i][0];
- outcoord[i][1] = coord[i][1];
- }
-}
-
-static void eval_points2( GLfloat outcoord[][4],
- GLfloat coord[][4],
- const GLuint *flags,
- GLuint start,
- GLfloat du, GLfloat u1,
- GLfloat dv, GLfloat v1 )
-{
- GLuint i;
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & VERT_EVAL_P2) {
- outcoord[i][0] = coord[i][0] * du + u1;
- outcoord[i][1] = coord[i][1] * dv + v1;
- } else if (flags[i] & VERT_EVAL_ANY) {
- outcoord[i][0] = coord[i][0];
- outcoord[i][1] = coord[i][1];
- }
-}
-
-
-static const GLubyte dirty_flags[5] = {
- 0, /* not possible */
- VEC_DIRTY_0,
- VEC_DIRTY_1,
- VEC_DIRTY_2,
- VEC_DIRTY_3
-};
-
-
-static GLvector4f *eval1_4f( GLvector4f *dest,
- GLfloat coord[][4],
- const GLuint *flags,
- GLuint start,
- GLuint dimension,
- struct gl_1d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- GLfloat (*to)[4] = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C1|VERT_EVAL_P1)) {
- GLfloat u = (coord[i][0] - u1) * du;
- ASSIGN_4V(to[i], 0,0,0,1);
- horner_bezier_curve(map->Points, to[i], u, dimension, map->Order);
- }
-
- dest->count = i;
- dest->start = VEC_ELT(dest, GLfloat, start);
- dest->size = MAX2(dest->size, dimension);
- dest->flags |= dirty_flags[dimension];
- return dest;
-}
-
-
-static GLvector1ui *eval1_1ui( GLvector1ui *dest,
- GLfloat coord[][4],
- const GLuint *flags,
- GLuint start,
- struct gl_1d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- GLuint *to = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C1|VERT_EVAL_P1)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat tmp;
- horner_bezier_curve(map->Points, &tmp, u, 1, map->Order);
- to[i] = (GLuint) (GLint) tmp;
- }
-
- dest->start = VEC_ELT(dest, GLuint, start);
- dest->count = i;
- return dest;
-}
-
-static GLvector3f *eval1_norm( GLvector3f *dest,
- GLfloat coord[][4],
- GLuint *flags, /* not const */
- GLuint start,
- struct gl_1d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- GLfloat (*to)[3] = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C1|VERT_EVAL_P1)) {
- GLfloat u = (coord[i][0] - u1) * du;
- horner_bezier_curve(map->Points, to[i], u, 3, map->Order);
- flags[i+1] |= VERT_NORM; /* reset */
- }
-
- dest->start = VEC_ELT(dest, GLfloat, start);
- dest->count = i;
- return dest;
-}
-
-static GLvector4ub *eval1_color( GLvector4ub *dest,
- GLfloat coord[][4],
- GLuint *flags, /* not const */
- GLuint start,
- struct gl_1d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- GLubyte (*to)[4] = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C1|VERT_EVAL_P1)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat fcolor[4];
- horner_bezier_curve(map->Points, fcolor, u, 4, map->Order);
- FLOAT_RGBA_TO_CHAN_RGBA(to[i], fcolor);
- flags[i+1] |= VERT_RGBA; /* reset */
- }
-
- dest->start = VEC_ELT(dest, GLubyte, start);
- dest->count = i;
- return dest;
-}
-
-
-
-
-static GLvector4f *eval2_obj_norm( GLvector4f *obj_ptr,
- GLvector3f *norm_ptr,
- GLfloat coord[][4],
- GLuint *flags,
- GLuint start,
- GLuint dimension,
- struct gl_2d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- const GLfloat v1 = map->v1;
- const GLfloat dv = map->dv;
- GLfloat (*obj)[4] = obj_ptr->data;
- GLfloat (*normal)[3] = norm_ptr->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C2|VERT_EVAL_P2)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat v = (coord[i][1] - v1) * dv;
- GLfloat du[4], dv[4];
-
- ASSIGN_4V(obj[i], 0,0,0,1);
- de_casteljau_surf(map->Points, obj[i], du, dv, u, v, dimension,
- map->Uorder, map->Vorder);
-
- CROSS3(normal[i], du, dv);
- NORMALIZE_3FV(normal[i]);
- flags[i+1] |= VERT_NORM;
- }
-
- obj_ptr->start = VEC_ELT(obj_ptr, GLfloat, start);
- obj_ptr->count = i;
- obj_ptr->size = MAX2(obj_ptr->size, dimension);
- obj_ptr->flags |= dirty_flags[dimension];
- return obj_ptr;
-}
-
-
-static GLvector4f *eval2_4f( GLvector4f *dest,
- GLfloat coord[][4],
- const GLuint *flags,
- GLuint start,
- GLuint dimension,
- struct gl_2d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- const GLfloat v1 = map->v1;
- const GLfloat dv = map->dv;
- GLfloat (*to)[4] = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C2|VERT_EVAL_P2)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat v = (coord[i][1] - v1) * dv;
- horner_bezier_surf(map->Points, to[i], u, v, dimension,
- map->Uorder, map->Vorder);
- }
-
- dest->start = VEC_ELT(dest, GLfloat, start);
- dest->count = i;
- dest->size = MAX2(dest->size, dimension);
- dest->flags |= dirty_flags[dimension];
- return dest;
-}
-
-
-static GLvector3f *eval2_norm( GLvector3f *dest,
- GLfloat coord[][4],
- GLuint *flags,
- GLuint start,
- struct gl_2d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- const GLfloat v1 = map->v1;
- const GLfloat dv = map->dv;
- GLfloat (*to)[3] = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C2|VERT_EVAL_P2)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat v = (coord[i][1] - v1) * dv;
- horner_bezier_surf(map->Points, to[i], u, v, 3,
- map->Uorder, map->Vorder);
- flags[i+1] |= VERT_NORM; /* reset */
- }
-
- dest->start = VEC_ELT(dest, GLfloat, start);
- dest->count = i;
- return dest;
-}
-
-
-static GLvector1ui *eval2_1ui( GLvector1ui *dest,
- GLfloat coord[][4],
- const GLuint *flags,
- GLuint start,
- struct gl_2d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- const GLfloat v1 = map->v1;
- const GLfloat dv = map->dv;
- GLuint *to = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C2|VERT_EVAL_P2)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat v = (coord[i][1] - v1) * dv;
- GLfloat tmp;
- horner_bezier_surf(map->Points, &tmp, u, v, 1,
- map->Uorder, map->Vorder);
-
- to[i] = (GLuint) (GLint) tmp;
- }
-
- dest->start = VEC_ELT(dest, GLuint, start);
- dest->count = i;
- return dest;
-}
-
-
-
-static GLvector4ub *eval2_color( GLvector4ub *dest,
- GLfloat coord[][4],
- GLuint *flags,
- GLuint start,
- struct gl_2d_map *map )
-{
- const GLfloat u1 = map->u1;
- const GLfloat du = map->du;
- const GLfloat v1 = map->v1;
- const GLfloat dv = map->dv;
- GLubyte (*to)[4] = dest->data;
- GLuint i;
-
- for (i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (flags[i] & (VERT_EVAL_C2|VERT_EVAL_P2)) {
- GLfloat u = (coord[i][0] - u1) * du;
- GLfloat v = (coord[i][1] - v1) * dv;
- GLfloat fcolor[4];
- horner_bezier_surf(map->Points, fcolor, u, v, 4,
- map->Uorder, map->Vorder);
- FLOAT_RGBA_TO_CHAN_RGBA(to[i], fcolor);
- flags[i+1] |= VERT_RGBA; /* reset */
- }
-
- dest->start = VEC_ELT(dest, GLubyte, start);
- dest->count = i;
- return dest;
-}
-
-
-static GLvector4f *copy_4f( GLvector4f *out, CONST GLvector4f *in,
- const GLuint *flags,
- GLuint start )
-{
- GLfloat (*to)[4] = out->data;
- GLfloat (*from)[4] = in->data;
- GLuint i;
-
- for ( i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (!(flags[i] & VERT_EVAL_ANY))
- COPY_4FV( to[i], from[i] );
-
- out->start = VEC_ELT(out, GLfloat, start);
- return out;
-}
-
-static GLvector3f *copy_3f( GLvector3f *out, CONST GLvector3f *in,
- const GLuint *flags,
- GLuint start )
-{
- GLfloat (*to)[3] = out->data;
- GLfloat (*from)[3] = in->data;
- GLuint i;
-
- for ( i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (!(flags[i] & VERT_EVAL_ANY))
- COPY_3V( to[i], from[i] );
-
- out->start = VEC_ELT(out, GLfloat, start);
- return out;
-}
-
-static GLvector4ub *copy_4ub( GLvector4ub *out,
- CONST GLvector4ub *in,
- const GLuint *flags,
- GLuint start )
-{
- GLubyte (*to)[4] = out->data;
- GLubyte (*from)[4] = in->data;
- GLuint i;
-
- for ( i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (!(flags[i] & VERT_EVAL_ANY))
- COPY_4UBV( to[i], from[i] );
-
- out->start = VEC_ELT(out, GLubyte, start);
- return out;
-}
-
-static GLvector1ui *copy_1ui( GLvector1ui *out,
- CONST GLvector1ui *in,
- const GLuint *flags,
- GLuint start )
-{
- GLuint *to = out->data;
- CONST GLuint *from = in->data;
- GLuint i;
-
- for ( i = start ; !(flags[i] & VERT_END_VB) ; i++)
- if (!(flags[i] & VERT_EVAL_ANY))
- to[i] = from[i];
-
- out->start = VEC_ELT(out, GLuint, start);
- return out;
-}
-
-
-/* KW: Rewrote this to perform eval on a whole buffer at once.
- * Only evaluates active data items, and avoids scribbling
- * the source buffer if we are running from a display list.
- *
- * If the user (in this case looser) sends eval coordinates
- * or runs a display list containing eval coords with no
- * vertex maps enabled, we have to either copy all non-eval
- * data to a new buffer, or find a way of working around
- * the eval data. I choose the second option.
- *
- * KW: This code not reached by cva - use IM to access storage.
- */
-void gl_eval_vb( struct vertex_buffer *VB )
-{
- struct immediate *IM = VB->IM;
- GLcontext *ctx = VB->ctx;
- GLuint req = ctx->CVA.elt.inputs;
- GLfloat (*coord)[4] = VB->ObjPtr->data;
- GLuint *flags = VB->Flag;
- GLuint new_flags = 0;
-
-
- GLuint any_eval1 = VB->OrFlag & (VERT_EVAL_C1|VERT_EVAL_P1);
- GLuint any_eval2 = VB->OrFlag & (VERT_EVAL_C2|VERT_EVAL_P2);
- GLuint all_eval = IM->AndFlag & VERT_EVAL_ANY;
-
- /* Handle the degenerate cases.
- */
- if (any_eval1 && !ctx->Eval.Map1Vertex4 && !ctx->Eval.Map1Vertex3) {
- VB->PurgeFlags |= (VERT_EVAL_C1|VERT_EVAL_P1);
- VB->EarlyCull = 0;
- any_eval1 = GL_FALSE;
- }
-
- if (any_eval2 && !ctx->Eval.Map2Vertex4 && !ctx->Eval.Map2Vertex3) {
- VB->PurgeFlags |= (VERT_EVAL_C2|VERT_EVAL_P2);
- VB->EarlyCull = 0;
- any_eval2 = GL_FALSE;
- }
-
- /* KW: This really is a degenerate case - doing this disables
- * culling, and causes dummy values for the missing vertices to be
- * transformed and clip tested. It also forces the individual
- * cliptesting of each primitive in vb_render. I wish there was a
- * nice alternative, but I can't say I want to put effort into
- * optimizing such a bad usage of the library - I'd much rather
- * work on useful changes.
- */
- if (VB->PurgeFlags) {
- if (!any_eval1 && !any_eval2 && all_eval) VB->Count = VB->Start;
- gl_purge_vertices( VB );
- if (!any_eval1 && !any_eval2) return;
- } else
- VB->IndirectCount = VB->Count;
-
- /* Translate points into coords.
- */
- if (any_eval1 && (VB->OrFlag & VERT_EVAL_P1))
- {
- eval_points1( IM->Obj, coord, flags, IM->Start,
- ctx->Eval.MapGrid1du,
- ctx->Eval.MapGrid1u1);
-
- coord = IM->Obj;
- }
-
- if (any_eval2 && (VB->OrFlag & VERT_EVAL_P2))
- {
- eval_points2( IM->Obj, coord, flags, IM->Start,
- ctx->Eval.MapGrid2du,
- ctx->Eval.MapGrid2u1,
- ctx->Eval.MapGrid2dv,
- ctx->Eval.MapGrid2v1 );
-
- coord = IM->Obj;
- }
-
- /* Perform the evaluations on active data elements.
- */
- if (req & VERT_INDEX)
- {
- GLvector1ui *in_index = VB->IndexPtr;
- GLvector1ui *out_index = &IM->v.Index;
-
- if (ctx->Eval.Map1Index && any_eval1)
- VB->IndexPtr = eval1_1ui( out_index, coord, flags, IM->Start,
- &ctx->EvalMap.Map1Index );
-
- if (ctx->Eval.Map2Index && any_eval2)
- VB->IndexPtr = eval2_1ui( out_index, coord, flags, IM->Start,
- &ctx->EvalMap.Map2Index );
-
- if (VB->IndexPtr != in_index) {
- new_flags |= VERT_INDEX;
- if (!all_eval)
- VB->IndexPtr = copy_1ui( out_index, in_index, flags, IM->Start );
- }
- }
-
- if (req & VERT_RGBA)
- {
- GLvector4ub *in_color = VB->ColorPtr;
- GLvector4ub *out_color = &IM->v.Color;
-
- if (ctx->Eval.Map1Color4 && any_eval1)
- VB->ColorPtr = eval1_color( out_color, coord, flags, IM->Start,
- &ctx->EvalMap.Map1Color4 );
-
- if (ctx->Eval.Map2Color4 && any_eval2)
- VB->ColorPtr = eval2_color( out_color, coord, flags, IM->Start,
- &ctx->EvalMap.Map2Color4 );
-
- if (VB->ColorPtr != in_color) {
- new_flags |= VERT_RGBA;
- if (!all_eval)
- VB->ColorPtr = copy_4ub( out_color, in_color, flags, IM->Start );
- }
-
- VB->Color[0] = VB->Color[1] = VB->ColorPtr;
- }
-
-
- if (req & VERT_NORM)
- {
- GLvector3f *in_normal = VB->NormalPtr;
- GLvector3f *out_normal = &IM->v.Normal;
-
- if (ctx->Eval.Map1Normal && any_eval1)
- VB->NormalPtr = eval1_norm( out_normal, coord, flags, IM->Start,
- &ctx->EvalMap.Map1Normal );
-
- if (ctx->Eval.Map2Normal && any_eval2)
- VB->NormalPtr = eval2_norm( out_normal, coord, flags, IM->Start,
- &ctx->EvalMap.Map2Normal );
-
- new_flags |= VERT_NORM;
-
- if (VB->NormalPtr != in_normal) {
- if (!all_eval)
- VB->NormalPtr = copy_3f( out_normal, in_normal, flags, IM->Start );
- }
- }
-
-
- if (req & VERT_TEX_ANY(0))
- {
- GLvector4f *tc = VB->TexCoordPtr[0];
- GLvector4f *in = tc;
- GLvector4f *out = &IM->v.TexCoord[0];
-
- if (any_eval1) {
- if (ctx->Eval.Map1TextureCoord4)
- tc = eval1_4f( out, coord, flags, IM->Start,
- 4, &ctx->EvalMap.Map1Texture4);
- else if (ctx->Eval.Map1TextureCoord3)
- tc = eval1_4f( out, coord, flags, IM->Start, 3,
- &ctx->EvalMap.Map1Texture3);
- else if (ctx->Eval.Map1TextureCoord2)
- tc = eval1_4f( out, coord, flags, IM->Start, 2,
- &ctx->EvalMap.Map1Texture2);
- else if (ctx->Eval.Map1TextureCoord1)
- tc = eval1_4f( out, coord, flags, IM->Start, 1,
- &ctx->EvalMap.Map1Texture1);
- }
-
- if (any_eval2) {
- if (ctx->Eval.Map2TextureCoord4)
- tc = eval2_4f( out, coord, flags, IM->Start,
- 4, &ctx->EvalMap.Map2Texture4);
- else if (ctx->Eval.Map2TextureCoord3)
- tc = eval2_4f( out, coord, flags, IM->Start,
- 3, &ctx->EvalMap.Map2Texture3);
- else if (ctx->Eval.Map2TextureCoord2)
- tc = eval2_4f( out, coord, flags, IM->Start,
- 2, &ctx->EvalMap.Map2Texture2);
- else if (ctx->Eval.Map2TextureCoord1)
- tc = eval2_4f( out, coord, flags, IM->Start,
- 1, &ctx->EvalMap.Map2Texture1);
- }
-
- if (tc != in) {
- new_flags |= VERT_TEX_ANY(0); /* fix for sizes.. */
- if (!all_eval)
- tc = copy_4f( out, in, flags, IM->Start );
- }
-
- VB->TexCoordPtr[0] = tc;
- }
-
-
- {
- GLvector4f *in = VB->ObjPtr;
- GLvector4f *out = &IM->v.Obj;
- GLvector4f *obj = in;
-
- if (any_eval1) {
- if (ctx->Eval.Map1Vertex4)
- obj = eval1_4f( out, coord, flags, IM->Start,
- 4, &ctx->EvalMap.Map1Vertex4);
- else
- obj = eval1_4f( out, coord, flags, IM->Start,
- 3, &ctx->EvalMap.Map1Vertex3);
- }
-
- if (any_eval2) {
- GLvector3f *in_normal = VB->NormalPtr;
- GLvector3f *out_normal = &IM->v.Normal;
-
- if (ctx->Eval.Map2Vertex4)
- {
- if (ctx->Eval.AutoNormal && (req & VERT_NORM)) {
- obj = eval2_obj_norm( out, out_normal, coord, flags,
- IM->Start, 4, &ctx->EvalMap.Map2Vertex4 );
- VB->NormalPtr = out_normal;
- new_flags |= VERT_NORM;
- }
- else
- obj = eval2_4f( out, coord, flags, IM->Start,
- 4, &ctx->EvalMap.Map2Vertex4 );
- }
- else if (ctx->Eval.Map2Vertex3)
- {
- if (ctx->Eval.AutoNormal && (req & VERT_NORM)) {
- obj = eval2_obj_norm( out, out_normal, coord, flags,
- IM->Start, 3, &ctx->EvalMap.Map2Vertex3 );
- VB->NormalPtr = out_normal;
- new_flags |= VERT_NORM;
- }
- else
- obj = eval2_4f( out, coord, flags, IM->Start,
- 3, &ctx->EvalMap.Map2Vertex3 );
- }
-
-
- if (VB->NormalPtr != in_normal) {
- if (!all_eval)
- VB->NormalPtr = copy_3f( out_normal, in_normal, flags,
- IM->Start );
- }
- }
-
- if (obj != in && !all_eval)
- obj = copy_4f( out, in, flags, IM->Start );
-
- VB->ObjPtr = obj;
- }
-
- if (new_flags) {
- GLuint *oldflags = VB->Flag;
- GLuint *flags = VB->Flag = VB->EvaluatedFlags;
- GLuint i;
- GLuint count = VB->Count;
- GLuint andflag = VB->IM->AndFlag;
-
- if (!flags) {
- VB->EvaluatedFlags = (GLuint *) MALLOC(VB->Size * sizeof(GLuint));
- flags = VB->Flag = VB->EvaluatedFlags;
- }
-
- if (all_eval) {
- for (i = 0 ; i <= count ; i++)
- flags[i] = oldflags[i] | new_flags;
- andflag |= new_flags;
- } else {
- andflag = ~0;
- for (i = 0 ; i <= count ; i++) {
- flags[i] = oldflags[i];
- if (flags[i] & VERT_EVAL_ANY)
- flags[i] |= new_flags;
- andflag &= flags[i];
- }
- }
-
- VB->OrFlag |= new_flags;
- VB->CullMode = (GLubyte) ((andflag & VERT_NORM) ? 0 : COMPACTED_NORMALS);
- }
-}
-
-
-void