static void TraverseILS2D(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; M_IndexedLineSet2D *ils2D = (M_IndexedLineSet2D *)node; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } if (!ils2D->coord) return; ils2d_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { case TRAVERSE_DRAW_2D: ILS2D_Draw(node, tr_state); return; #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { stack->mesh = new_mesh(); mesh_new_ils(stack->mesh, ils2D->coord, &ils2D->coordIndex, ils2D->color, &ils2D->colorIndex, ils2D->colorPerVertex, 0); } if (ils2D->color) { DrawAspect2D asp; memset(&asp, 0, sizeof(DrawAspect2D)); drawable_get_aspect_2d_mpeg4(node, &asp, tr_state); visual_3d_mesh_strike(tr_state, stack->mesh, asp.pen_props.width, asp.line_scale, asp.pen_props.dash); } else { visual_3d_draw_2d(stack, tr_state); } return; #endif case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; /*ILS2D are NEVER filled*/ ctx->aspect.fill_color &= 0x00FFFFFF; drawable_finalize_sort(ctx, tr_state, NULL); return; default: return; } }
static void TraverseArc2D(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } arc2d_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { stack->mesh = new_mesh(); if (gf_node_get_tag(node)==TAG_X3D_Arc2D) { mesh_get_outline(stack->mesh, stack->path); } else { mesh_from_path(stack->mesh, stack->path); } } visual_3d_draw_2d(stack, tr_state); return; #endif case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); #ifndef GPAC_DISABLE_3D gf_bbox_from_rect(&tr_state->bbox, &tr_state->bounds); #endif return; case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; drawable_finalize_sort(ctx, tr_state, NULL); return; } }
static void TraverseIndexedCurve2D(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; IndexedCurve2D ic2d; GF_TraverseState *tr_state = (GF_TraverseState *)rs; Drawable *stack = (Drawable *)gf_node_get_private(node); if (is_destroy) { drawable_node_del(node); return; } if (gf_node_dirty_get(node)) { if (!IndexedCurve2D_GetNode(node, &ic2d)) return; curve2d_check_changes((GF_Node*) &ic2d, stack, tr_state, &ic2d.index); } switch (tr_state->traversing_mode) { #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { stack->mesh = new_mesh(); mesh_from_path(stack->mesh, stack->path); } visual_3d_draw_2d(stack, tr_state); return; #endif case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; drawable_finalize_sort(ctx, tr_state, NULL); return; } }
static void TraverseCircle(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } circle_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { Fixed a = ((M_Circle *) node)->radius * 2; stack->mesh = new_mesh(); mesh_new_ellipse(stack->mesh, a, a, tr_state->visual->compositor->high_speed); } visual_3d_draw_2d(stack, tr_state); return; #endif case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; drawable_finalize_sort(ctx, tr_state, NULL); return; } }
static void TraverseDisk2D(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } disk2d_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { stack->mesh = new_mesh(); /*FIXME - enable it with OpenGL-ES*/ mesh_from_path(stack->mesh, stack->path); } visual_3d_draw_2d(stack, tr_state); return; #endif case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; drawable_finalize_sort(ctx, tr_state, NULL); return; } }
static void TraverseRectangle(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } rectangle_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { case TRAVERSE_DRAW_2D: compositor_2d_draw_rectangle(tr_state); return; #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { stack->mesh = new_mesh(); mesh_new_rectangle(stack->mesh, ((M_Rectangle *) node)->size, NULL, 0); } visual_3d_draw_2d(stack, tr_state); return; #endif case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif break; default: return; } ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; /*if rotated, object is transparent (doesn't fill bounds) and antialias must be used*/ if (tr_state->transform.m[1] || tr_state->transform.m[3]) { } else { /*if alpha or not filled, transparent*/ if (ctx->aspect.fill_color && (GF_COL_A(ctx->aspect.fill_color) != 0xFF)) { } /*if texture transparent, transparent*/ else if (ctx->aspect.fill_texture && ctx->aspect.fill_texture->transparent) { } /*TODO check matrix for alpha*/ else if (!tr_state->color_mat.identity) { } /*otherwise, not transparent*/ else { ctx->flags &= ~CTX_IS_TRANSPARENT; } /*if no line width, we skip antialiasing*/ if (!ctx->aspect.pen_props.width) ctx->flags |= CTX_NO_ANTIALIAS; } drawable_finalize_sort(ctx, tr_state, NULL); }
static void TraverseOffscreenGroup(GF_Node *node, void *rs, Bool is_destroy) { OffscreenGroupStack *stack = (OffscreenGroupStack *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *) rs; if (is_destroy) { if (stack->cache) group_cache_del(stack->cache); gf_free(stack); return; } if (tr_state->traversing_mode==TRAVERSE_SORT) { if (!stack->detached && (gf_node_dirty_get(node) & GF_SG_NODE_DIRTY)) { OffscreenGroup_GetNode(node, &stack->og); if (stack->og.offscreen) { stack->flags |= GROUP_IS_CACHED | GROUP_PERMANENT_CACHE; if (!stack->cache) { stack->cache = group_cache_new(tr_state->visual->compositor, (GF_Node*)&stack->og); } stack->cache->opacity = stack->og.opacity; stack->cache->drawable->flags |= DRAWABLE_HAS_CHANGED; } else { if (stack->cache) group_cache_del(stack->cache); stack->cache = NULL; stack->flags &= ~(GROUP_IS_CACHED|GROUP_PERMANENT_CACHE); } gf_node_dirty_clear(node, GF_SG_NODE_DIRTY); /*flag is not set for PROTO*/ gf_node_dirty_set(node, GF_SG_CHILD_DIRTY, 0); } if (stack->cache) { if (stack->detached) gf_node_dirty_clear(node, GF_SG_CHILD_DIRTY); tr_state->subscene_not_over = 0; group_cache_traverse((GF_Node *)&stack->og, stack->cache, tr_state, stack->cache->force_recompute, 1, stack->detached ? 1 : 0); if (gf_node_dirty_get(node)) { gf_node_dirty_clear(node, GF_SG_CHILD_DIRTY); } else if ((stack->og.offscreen==2) && !stack->detached && !tr_state->subscene_not_over && stack->cache->txh.width && stack->cache->txh.height) { GF_FieldInfo field; if (gf_node_get_field(node, 0, &field) == GF_OK) { gf_node_unregister_children(node, *(GF_ChildNodeItem **) field.far_ptr); *(GF_ChildNodeItem **) field.far_ptr = NULL; stack->detached = 1; } if (gf_node_get_field(node, 3, &field) == GF_OK) { *(SFBool *) field.far_ptr = 1; //gf_node_event_out(node, 3); } } } else { group_2d_traverse((GF_Node *)&stack->og, (GroupingNode2D*)stack, tr_state); } } /*draw mode*/ else if (stack->cache && (tr_state->traversing_mode == TRAVERSE_DRAW_2D)) { /*draw it*/ group_cache_draw(stack->cache, tr_state); gf_node_dirty_clear(node, GF_SG_CHILD_DIRTY); } else if (!stack->detached) { group_2d_traverse((GF_Node *)&stack->og, (GroupingNode2D*)stack, tr_state); } else { if (tr_state->traversing_mode == TRAVERSE_GET_BOUNDS) { tr_state->bounds = stack->bounds; } else if (tr_state->traversing_mode == TRAVERSE_PICK) { vrml_drawable_pick(stack->cache->drawable, tr_state); } } }
static void TraverseTriangleSet2D(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } triangleset2d_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: if (!stack->mesh) { SFColorRGBA col; u32 i, count, idx; GF_Vertex v1, v2, v3; X_TriangleSet2D *p = (X_TriangleSet2D *)node; stack->mesh = new_mesh(); stack->mesh->mesh_type = MESH_TRIANGLES; col.red = col.green = col.blue = 0; col.alpha = FIX_ONE; v1.color = MESH_MAKE_COL(col); v1.normal.x = v1.normal.y = 0; v1.normal.z = MESH_NORMAL_UNIT; v1.pos.z = 0; v3 = v2 = v1; count = p->vertices.count; while (count%3) count--; for (i=0; i<count; i+=3) { idx = stack->mesh->v_count; v1.pos.x = p->vertices.vals[i].x; v1.pos.y = p->vertices.vals[i].y; v2.pos.x = p->vertices.vals[i+1].x; v2.pos.y = p->vertices.vals[i+1].y; v3.pos.x = p->vertices.vals[i+2].x; v3.pos.y = p->vertices.vals[i+2].y; mesh_set_vertex_vx(stack->mesh, &v1); mesh_set_vertex_vx(stack->mesh, &v2); mesh_set_vertex_vx(stack->mesh, &v3); gf_vec_diff(v2.pos, v2.pos, v1.pos); gf_vec_diff(v3.pos, v3.pos, v1.pos); v1.pos = gf_vec_cross(v2.pos, v3.pos); if (v1.pos.z<0) { mesh_set_triangle(stack->mesh, idx, idx+2, idx+1); } else { mesh_set_triangle(stack->mesh, idx, idx+1, idx+2); } } stack->mesh->flags |= MESH_IS_2D; mesh_update_bounds(stack->mesh); } visual_3d_draw_2d(stack, tr_state); return; #endif case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; drawable_finalize_sort(ctx, tr_state, NULL); return; } }
static void TraverseIFS2D(GF_Node *node, void *rs, Bool is_destroy) { DrawableContext *ctx; M_IndexedFaceSet2D *ifs2D = (M_IndexedFaceSet2D *)node; Drawable *stack = (Drawable *)gf_node_get_private(node); GF_TraverseState *tr_state = (GF_TraverseState *)rs; if (is_destroy) { drawable_node_del(node); return; } if (!ifs2D->coord) return; ifs2d_check_changes(node, stack, tr_state); switch (tr_state->traversing_mode) { case TRAVERSE_DRAW_2D: IFS2D_Draw(node, tr_state); return; #ifndef GPAC_DISABLE_3D case TRAVERSE_DRAW_3D: { DrawAspect2D asp; if (!stack->mesh) { stack->mesh = new_mesh(); mesh_new_ifs2d(stack->mesh, node); } memset(&asp, 0, sizeof(DrawAspect2D)); drawable_get_aspect_2d_mpeg4(node, &asp, tr_state); if (ifs2D->color && !GF_COL_A(asp.fill_color) ) { /*use special func to disable outline recompute and handle recompute ourselves*/ StrikeInfo2D *si = drawable_get_strikeinfo(tr_state->visual->compositor, stack, &asp, tr_state->appear, NULL, 0, tr_state); if (!si->mesh_outline) { si->mesh_outline = new_mesh(); mesh_new_ils(si->mesh_outline, ifs2D->coord, &ifs2D->coordIndex, ifs2D->color, &ifs2D->colorIndex, ifs2D->colorPerVertex, 1); } visual_3d_mesh_strike(tr_state, si->mesh_outline, asp.pen_props.width, asp.line_scale, asp.pen_props.dash); } else { visual_3d_draw_2d_with_aspect(stack, tr_state, &asp); } return; } #endif case TRAVERSE_PICK: vrml_drawable_pick(stack, tr_state); return; case TRAVERSE_GET_BOUNDS: gf_path_get_bounds(stack->path, &tr_state->bounds); return; case TRAVERSE_SORT: #ifndef GPAC_DISABLE_3D if (tr_state->visual->type_3d) return; #endif ctx = drawable_init_context_mpeg4(stack, tr_state); if (!ctx) return; drawable_finalize_sort(ctx, tr_state, NULL); return; } }