Bool c2d_gl_draw_bitmap(GF_VisualManager *visual, GF_TraverseState *tr_state, DrawableContext *ctx, GF_ColorKey *col_key) { u8 alpha = GF_COL_A(ctx->aspect.fill_color); if (ctx->transform.m[1] || ctx->transform.m[3]) return 0; visual_3d_set_state(visual, V3D_STATE_LIGHT, 0); visual_3d_enable_antialias(visual, 0); if (alpha && (alpha != 0xFF)) { visual_3d_set_material_2d_argb(visual, ctx->aspect.fill_color); gf_sc_texture_set_blend_mode(ctx->aspect.fill_texture, TX_MODULATE); } else if (gf_sc_texture_is_transparent(ctx->aspect.fill_texture)) { gf_sc_texture_set_blend_mode(ctx->aspect.fill_texture, TX_REPLACE); } else { visual_3d_set_state(visual, V3D_STATE_BLEND, 0); } /*ignore texture transform for bitmap*/ tr_state->mesh_num_textures = gf_sc_texture_enable(ctx->aspect.fill_texture, tr_state->appear ? ((M_Appearance *)tr_state->appear)->textureTransform : NULL); if (tr_state->mesh_num_textures) { SFVec2f size, orig; GF_Mesh *mesh; size.x = ctx->bi->unclip.width; size.y = ctx->bi->unclip.height; orig.x = ctx->bi->unclip.x + INT2FIX(visual->compositor->vp_width)/2; orig.y = INT2FIX(visual->compositor->vp_height)/2 - ctx->bi->unclip.y + ctx->bi->unclip.height; mesh = new_mesh(); mesh_new_rectangle(mesh, size, &orig, 1); visual_3d_mesh_paint(tr_state, mesh); mesh_free(mesh); gf_sc_texture_disable(ctx->aspect.fill_texture); tr_state->mesh_num_textures = 0; return 1; } return 0; }
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); }
void compositor_3d_draw_bitmap(Drawable *stack, DrawAspect2D *asp, GF_TraverseState *tr_state, Fixed width, Fixed height, Fixed bmp_scale_x, Fixed bmp_scale_y) { u8 alpha; GF_TextureHandler *txh; GF_Compositor *compositor = tr_state->visual->compositor; if (!asp->fill_texture) return; txh = asp->fill_texture; if (!txh || !txh->tx_io || !txh->width || !txh->height) return; if (((txh->pixelformat==GF_PIXEL_RGBD) || (txh->pixelformat==GF_PIXEL_YUVD))) { if (compositor->depth_gl_type) { if (txh->data && gf_sc_texture_convert(txh) ) visual_3d_point_sprite(tr_state->visual, stack, txh, tr_state); return; } } alpha = GF_COL_A(asp->fill_color); /*THIS IS A HACK, will not work when setting filled=0, transparency and XLineProps*/ if (!alpha) alpha = GF_COL_A(asp->line_color); visual_3d_set_state(tr_state->visual, V3D_STATE_LIGHT, GF_FALSE); visual_3d_enable_antialias(tr_state->visual, GF_FALSE); if (alpha && (alpha != 0xFF)) { visual_3d_set_material_2d_argb(tr_state->visual, GF_COL_ARGB(alpha, 0xFF, 0xFF, 0xFF)); gf_sc_texture_set_blend_mode(txh, TX_MODULATE); } else if (gf_sc_texture_is_transparent(txh)) { gf_sc_texture_set_blend_mode(txh, TX_REPLACE); } else { visual_3d_set_state(tr_state->visual, V3D_STATE_BLEND, GF_FALSE); } /*ignore texture transform for bitmap*/ tr_state->mesh_num_textures = gf_sc_texture_enable(txh, NULL); if (tr_state->mesh_num_textures) { /*we must check the w & h passed are correct because of bitmap node initialization*/ if (width && height) { if (!stack->mesh) { SFVec2f size; size.x = width; size.y = height; stack->mesh = new_mesh(); mesh_new_rectangle(stack->mesh, size, NULL, GF_FALSE); } } if (stack->mesh) { #ifdef GF_SR_USE_DEPTH if (tr_state->depth_offset) { GF_Matrix mx; Fixed offset; Fixed disp_depth = (compositor->display_depth<0) ? INT2FIX(tr_state->visual->height) : INT2FIX(compositor->display_depth); if (disp_depth) { GF_Matrix bck_mx; if (!tr_state->pixel_metrics) disp_depth = gf_divfix(disp_depth, tr_state->min_hsize); gf_mx_init(mx); /*add recalibration by the scene*/ offset = tr_state->depth_offset; if (tr_state->visual->depth_vp_range) { offset = gf_divfix(offset, tr_state->visual->depth_vp_range/2); } gf_mx_add_translation(&mx, 0, 0, gf_mulfix(offset, disp_depth/2) ); gf_mx_copy(bck_mx, tr_state->model_matrix); gf_mx_add_matrix(&tr_state->model_matrix, &mx); visual_3d_mesh_paint(tr_state, stack->mesh); gf_mx_copy(tr_state->model_matrix, bck_mx); } else { visual_3d_mesh_paint(tr_state, stack->mesh); } } else #endif visual_3d_mesh_paint(tr_state, stack->mesh); } gf_sc_texture_disable(txh); tr_state->mesh_num_textures = 0; } }
void compositor_3d_draw_bitmap(Drawable *stack, DrawAspect2D *asp, GF_TraverseState *tr_state, Fixed width, Fixed height, Fixed bmp_scale_x, Fixed bmp_scale_y) { u8 alpha; #if !defined(GPAC_USE_OGL_ES) && !defined(GPAC_USE_TINYGL) Fixed x, y; Fixed sx, sy; char *data; u32 format; #endif GF_TextureHandler *txh; GF_Compositor *compositor = tr_state->visual->compositor; Bool use_texture = !compositor->bitmap_use_pixels; if (!asp->fill_texture) return; txh = asp->fill_texture; if (!txh || !txh->tx_io || !txh->width || !txh->height) return; if (((txh->pixelformat==GF_PIXEL_RGBD) || (txh->pixelformat==GF_PIXEL_YUVD))) { if (compositor->depth_gl_type) { if (txh->data && gf_sc_texture_convert(txh) ) visual_3d_point_sprite(tr_state->visual, stack, txh, tr_state); return; } else { use_texture = 1; } } alpha = GF_COL_A(asp->fill_color); /*THIS IS A HACK, will not work when setting filled=0, transparency and XLineProps*/ if (!alpha) alpha = GF_COL_A(asp->line_color); /*texture is available in hw, use it - if blending, force using texture*/ if (!gf_sc_texture_needs_reload(txh) || (alpha != 0xFF) || use_texture #ifdef GF_SR_USE_DEPTH || tr_state->depth_offset #endif ) { visual_3d_set_state(tr_state->visual, V3D_STATE_LIGHT, 0); visual_3d_enable_antialias(tr_state->visual, 0); if (alpha && (alpha != 0xFF)) { visual_3d_set_material_2d_argb(tr_state->visual, GF_COL_ARGB(alpha, 0xFF, 0xFF, 0xFF)); gf_sc_texture_set_blend_mode(txh, TX_MODULATE); } else if (gf_sc_texture_is_transparent(txh)) { gf_sc_texture_set_blend_mode(txh, TX_REPLACE); } else { visual_3d_set_state(tr_state->visual, V3D_STATE_BLEND, 0); } /*ignore texture transform for bitmap*/ tr_state->mesh_num_textures = gf_sc_texture_enable(txh, NULL); if (tr_state->mesh_num_textures) { /*we must check the w & h passed are correct because of bitmap node initialization*/ if (width && height) { if (!stack->mesh) { SFVec2f size; size.x = width; size.y = height; stack->mesh = new_mesh(); mesh_new_rectangle(stack->mesh, size, NULL, 0); } } if (stack->mesh) { #ifdef GF_SR_USE_DEPTH if (tr_state->depth_offset) { GF_Matrix mx; Fixed offset; Fixed disp_depth = (compositor->display_depth<0) ? INT2FIX(tr_state->visual->height) : INT2FIX(compositor->display_depth); if (disp_depth) { if (!tr_state->pixel_metrics) disp_depth = gf_divfix(disp_depth, tr_state->min_hsize); gf_mx_init(mx); /*add recalibration by the scene*/ offset = tr_state->depth_offset; if (tr_state->visual->depth_vp_range) { offset = gf_divfix(offset, tr_state->visual->depth_vp_range/2); } gf_mx_add_translation(&mx, 0, 0, gf_mulfix(offset, disp_depth/2) ); visual_3d_matrix_push(tr_state->visual); visual_3d_matrix_add(tr_state->visual, mx.m); visual_3d_mesh_paint(tr_state, stack->mesh); visual_3d_matrix_pop(tr_state->visual); } else { visual_3d_mesh_paint(tr_state, stack->mesh); } } else #endif visual_3d_mesh_paint(tr_state, stack->mesh); } gf_sc_texture_disable(txh); tr_state->mesh_num_textures = 0; return; } } /*otherwise use glDrawPixels*/ #if !defined(GPAC_USE_OGL_ES) && !defined(GPAC_USE_TINYGL) data = gf_sc_texture_get_data(txh, &format); if (!data) return; x = INT2FIX(txh->width) / -2; y = INT2FIX(txh->height) / 2; { Fixed g[16]; sx = bmp_scale_x; if (sx<0) sx = FIX_ONE; sy = bmp_scale_y; if (sy<0) sy = FIX_ONE; #ifndef GPAC_DISABLE_VRML compositor_adjust_scale(txh->owner, &sx, &sy); #endif /*add top level scale if any*/ sx = gf_mulfix(sx, compositor->scale_x); sy = gf_mulfix(sy, compositor->scale_y); /*get & apply current transform scale*/ visual_3d_matrix_get(tr_state->visual, V3D_MATRIX_MODELVIEW, g); if (g[0]<0) g[0] *= -FIX_ONE; if (g[5]<0) g[5] *= -FIX_ONE; sx = gf_mulfix(sx, g[0]); sy = gf_mulfix(sy, g[5]); x = gf_mulfix(x, sx); y = gf_mulfix(y, sy); } visual_3d_draw_image(tr_state->visual, x, y, txh->width, txh->height, format, data, sx, sy); #endif }