static void composite_traverse(GF_Node *node, void *rs, Bool is_destroy)
{
	if (is_destroy) {
		u32 i=0;
		GF_VisualManager *a_visual;
		CompositeTextureStack *st = (CompositeTextureStack *) gf_node_get_private(node);
		/*unregister visual*/
		gf_sc_visual_unregister(st->visual->compositor, st->visual);

		/*We must make sure we don't keep pointers to this composite in the different visuals.
		  - we must track Appearance nodes at the compositor level to undo the textureTransform while picking
		  - but we clearly don't want to track destruction of all appearance nodes just to solve this texture delete
				=> remove the entire compositeTexture appearance state - this may lead to small bugs in interaction logics, however they should
				not be too damageable
		*/
		st->visual->compositor->hit_appear = NULL;
		st->visual->compositor->prev_hit_appear = NULL;

		while ( (a_visual = gf_list_enum(st->visual->compositor->visuals, &i))) {
			if (a_visual->offscreen) {
				CompositeTextureStack *a_st = (CompositeTextureStack *) gf_node_get_private(a_visual->offscreen);
				a_st->prev_hit_appear = NULL;
			}
		}

		visual_del(st->visual);
		if (st->txh.data) gf_free(st->txh.data);
		/*destroy texture*/
		gf_sc_texture_destroy(&st->txh);
#ifdef GPAC_USE_TINYGL
		if (st->tgl_ctx) ostgl_delete_context(st->tgl_ctx);
#endif
		gf_list_del(st->sensors);
		gf_list_del(st->previous_sensors);

		gf_free(st);
	} else {
		gf_node_traverse_children(node, rs);
	}
}
Example #2
0
static void TraverseUntransform(GF_Node *node, void *rs, Bool is_destroy)
{
    UntransformStack *stack = (UntransformStack *)gf_node_get_private(node);
    GF_TraverseState *tr_state = (GF_TraverseState *) rs;

    if (is_destroy) {
        gf_free(stack);
        return;
    }

    if (tr_state->traversing_mode==TRAVERSE_SORT) {
        if (gf_node_dirty_get(node)) {
            Untransform_GetNode(node, &stack->untr); /*lets place it below*/
            gf_node_dirty_clear(node, GF_SG_NODE_DIRTY);
        }
    }

#ifndef GPAC_DISABLE_3D
    if (tr_state->visual->type_3d) {
        GF_Matrix mx_model;
        GF_Camera backup_cam;

        if (!tr_state->camera) return;

        gf_mx_copy(mx_model, tr_state->model_matrix);
        gf_mx_init(tr_state->model_matrix);

        memcpy(&backup_cam, tr_state->camera, sizeof(GF_Camera));


        camera_invalidate(tr_state->camera);
        tr_state->camera->is_3D=0;
        tr_state->camera->flags |= CAM_NO_LOOKAT;
        tr_state->camera->end_zoom = FIX_ONE;
        camera_update(tr_state->camera, NULL, 1);


        if (tr_state->traversing_mode == TRAVERSE_SORT) {
            visual_3d_set_matrix_mode(tr_state->visual, V3D_MATRIX_PROJECTION);
            visual_3d_matrix_load(tr_state->visual, tr_state->camera->projection.m);
            visual_3d_set_matrix_mode(tr_state->visual, V3D_MATRIX_MODELVIEW);
            visual_3d_matrix_load(tr_state->visual, tr_state->camera->modelview.m);

            visual_3d_set_viewport(tr_state->visual, tr_state->camera->vp);

            gf_node_traverse_children((GF_Node *)&stack->untr, tr_state);

            gf_mx_copy(tr_state->model_matrix, mx_model);
            memcpy(tr_state->camera, &backup_cam, sizeof(GF_Camera));

            visual_3d_set_matrix_mode(tr_state->visual, V3D_MATRIX_PROJECTION);
            visual_3d_matrix_load(tr_state->visual, tr_state->camera->projection.m);
            visual_3d_set_matrix_mode(tr_state->visual, V3D_MATRIX_MODELVIEW);
            visual_3d_matrix_load(tr_state->visual, tr_state->camera->modelview.m);

            visual_3d_set_viewport(tr_state->visual, tr_state->camera->vp);
        } else if (tr_state->traversing_mode == TRAVERSE_PICK) {
            Fixed prev_dist = tr_state->visual->compositor->hit_square_dist;
            GF_Ray r = tr_state->ray;
            tr_state->ray.orig.x = INT2FIX(tr_state->pick_x);
            tr_state->ray.orig.y = INT2FIX(tr_state->pick_y);
            tr_state->ray.orig.z = 0;
            tr_state->ray.dir.x = 0;
            tr_state->ray.dir.y = 0;
            tr_state->ray.dir.z = -FIX_ONE;
            tr_state->visual->compositor->hit_square_dist=0;

            gf_node_traverse_children((GF_Node *)&stack->untr, tr_state);

            gf_mx_copy(tr_state->model_matrix, mx_model);
            memcpy(tr_state->camera, &backup_cam, sizeof(GF_Camera));
            tr_state->ray = r;

            /*nothing picked, restore previous pick*/
            if (!tr_state->visual->compositor->hit_square_dist)
                tr_state->visual->compositor->hit_square_dist = prev_dist;

        } else {
            gf_node_traverse_children((GF_Node *)&stack->untr, tr_state);

            gf_mx_copy(tr_state->model_matrix, mx_model);
            memcpy(tr_state->camera, &backup_cam, sizeof(GF_Camera));
        }

    } else
#endif
    {
        GF_Matrix2D mx2d_backup;
        gf_mx2d_copy(mx2d_backup, tr_state->transform);
        gf_mx2d_init(tr_state->transform);

        group_2d_traverse((GF_Node *)&stack->untr, (GroupingNode2D *)stack, tr_state);

        gf_mx2d_copy(tr_state->transform, mx2d_backup);


    }
}