#ifndef _VISUAL_MANAGER_3D_
#define _VISUAL_MANAGER_3D_
#include <gpac/internal/compositor_dev.h>
#ifndef GPAC_DISABLE_3D
#define GF_MAX_GL_CLIPS 2
#define GF_MAX_GL_LIGHTS 4
Bool visual_3d_draw_frame(GF_VisualManager *visual, GF_Node *root, GF_TraverseState *tr_state, Bool is_root_visual);
void visual_3d_pick_node(GF_VisualManager *visual, GF_TraverseState *tr_state, GF_Event *ev, GF_ChildNodeItem *children);
Bool visual_3d_node_cull(GF_TraverseState *tr_state, GF_BBox *bbox, Bool skip_near);
void visual_3d_viewpoint_change(GF_TraverseState *tr_state, GF_Node *vp, Bool animate_change, Fixed fieldOfView, SFVec3f position, SFRotation orientation, SFVec3f local_center);
#ifndef GPAC_DISABLE_VRML
void visual_3d_vrml_drawable_pick(GF_Node *n, GF_TraverseState *tr_state, GF_Mesh *mesh, Drawable *drawable) ;
void visual_3d_vrml_drawable_collide(GF_Node *node, GF_TraverseState *tr_state);
#endif
void visual_3d_register_context(GF_TraverseState *tr_state, GF_Node *node_to_draw);
void visual_3d_flush_contexts(GF_VisualManager *visual, GF_TraverseState *tr_state);
void visual_3d_draw(GF_TraverseState *tr_state, GF_Mesh *mesh);
void visual_3d_draw_2d_with_aspect(Drawable *st, GF_TraverseState *tr_state, DrawAspect2D *asp);
void visual_3d_draw_from_context(DrawableContext *ctx, GF_TraverseState *tr_state);
#ifndef GPAC_DISABLE_VRML
void visual_3d_draw_2d(Drawable *st, GF_TraverseState *tr_state);
#endif
void visual_3d_set_2d_strike(GF_TraverseState *tr_state, DrawAspect2D *asp);
Bool visual_3d_setup_appearance(GF_TraverseState *tr_state);
Bool visual_3d_setup_texture(GF_TraverseState *tr_state, Fixed diffuse_alpha);
void visual_3d_disable_texture(GF_TraverseState *tr_state);
void visual_3d_check_collisions(GF_TraverseState *tr_state, GF_Node *root_node, GF_ChildNodeItem *node_list);
void visual_3d_init_draw(GF_TraverseState *tr_state, u32 layer_type);
void visual_3d_setup_projection(GF_TraverseState *tr_state, Bool is_layer);
typedef struct
{
GF_Mesh *mesh;
} Drawable3D;
Drawable3D *drawable_3d_new(GF_Node *node);
void drawable_3d_del(GF_Node *n);
void drawable_3d_base_traverse(GF_Node *n, void *rs, Bool is_destroy, void (*build_shape)(GF_Node*,Drawable3D *,GF_TraverseState *) );
void drawable3d_check_focus_highlight(GF_Node *node, GF_TraverseState *tr_state, GF_BBox *orig_bounds);
typedef struct
{
GF_Node *dlight;
GF_Matrix light_matrix;
} DirectionalLightContext;
typedef struct
{
GF_Node *geometry;
GF_Node *appearance;
GF_Matrix model_matrix;
GF_ColorMatrix color_mat;
u32 text_split_idx;
Bool pixel_metrics;
u32 cull_flag;
GF_List *directional_lights;
Fixed zmax;
GF_Rect clipper;
Bool has_clipper;
GF_Plane clip_planes[MAX_USER_CLIP_PLANES];
u32 num_clip_planes;
#ifdef GF_SR_USE_DEPTH
Fixed depth_offset;
#endif
} Drawable3DContext;
typedef struct
{
u32 type;
SFVec3f direction, position, attenuation;
Fixed ambientIntensity, intensity, beamWidth, cutOffAngle;
SFColor color;
GF_Matrix light_mx;
} GF_LightInfo;
typedef struct
{
GF_Plane p;
Bool is_2d_clip;
GF_Matrix *mx_clipper;
} GF_ClipInfo;
void visual_3d_setup(GF_VisualManager *visual);
void visual_3d_enable_depth_buffer(GF_VisualManager *visual, Bool on);
void visual_3d_enable_antialias(GF_VisualManager *visual, Bool bOn);
void visual_3d_enable_headlight(GF_VisualManager *visual, Bool bOn, GF_Camera *cam);
enum
{
V3D_STATE_LIGHT = 1,
V3D_STATE_BLEND = (1<<1),
V3D_STATE_COLOR = (1<<2)
};
void visual_3d_set_state(GF_VisualManager *visual, u32 flag_mask, Bool setOn);
void visual_3d_clear(GF_VisualManager *visual, SFColor color, Fixed alpha);
void visual_3d_clear_depth(GF_VisualManager *visual);
void visual_3d_set_background_state(GF_VisualManager *visual, Bool on);
void visual_3d_set_texture_matrix(GF_VisualManager *visual, GF_Matrix *mx);
void visual_3d_projection_matrix_modified(GF_VisualManager *visual);
void visual_3d_set_viewport(GF_VisualManager *visual, GF_Rect vp);
void visual_3d_set_scissor(GF_VisualManager *visual, GF_Rect *vp);
void visual_3d_set_clipper_2d(GF_VisualManager *visual, GF_Rect clip, GF_Matrix *mx_at_clipper);
void visual_3d_reset_clipper_2d(GF_VisualManager *visual);
void visual_3d_set_clip_plane(GF_VisualManager *visual, GF_Plane p, GF_Matrix *mx_at_clipper, Bool is_2d_clip);
void visual_3d_reset_clip_plane(GF_VisualManager *visual);
void visual_3d_mesh_paint(GF_TraverseState *tr_state, GF_Mesh *mesh);
void visual_3d_mesh_strike(GF_TraverseState *tr_state, GF_Mesh *mesh, Fixed width, Fixed line_scale, u32 dash_style);
enum
{
V3D_MATERIAL_AMBIENT=0,
V3D_MATERIAL_DIFFUSE,
V3D_MATERIAL_SPECULAR,
V3D_MATERIAL_EMISSIVE,
};
void visual_3d_set_material(GF_VisualManager *visual, u32 material_type, Fixed *rgba);
void visual_3d_set_shininess(GF_VisualManager *visual, Fixed shininess);
void visual_3d_set_material_2d(GF_VisualManager *visual, SFColor col, Fixed alpha);
void visual_3d_set_material_2d_argb(GF_VisualManager *visual, u32 col);
void visual_3d_remove_last_light(GF_VisualManager *visual);
void visual_3d_clear_all_lights(GF_VisualManager *visual);
Bool visual_3d_add_spot_light(GF_VisualManager *visual, Fixed ambientIntensity, SFVec3f attenuation, Fixed beamWidth,
SFColor color, Fixed cutOffAngle, SFVec3f direction, Fixed intensity, SFVec3f location, GF_Matrix *light_mx);
Bool visual_3d_add_point_light(GF_VisualManager *visual, Fixed ambientIntensity, SFVec3f attenuation, SFColor color, Fixed intensity, SFVec3f location, GF_Matrix *light_mx);
Bool visual_3d_add_directional_light(GF_VisualManager *visual, Fixed ambientIntensity, SFColor color, Fixed intensity, SFVec3f direction, GF_Matrix *light_mx);
void visual_3d_has_inactive_light(GF_VisualManager *visual);
void visual_3d_set_fog(GF_VisualManager *visual, const char *type, SFColor color, Fixed density, Fixed visibility);
void visual_3d_fill_rect(GF_VisualManager *visual, GF_Rect rc, SFColorRGBA color);
void visual_3d_point_sprite(GF_VisualManager *visual, Drawable *stack, GF_TextureHandler *txh, GF_TraverseState *tr_state);
#ifndef GPAC_USE_GLES1X
void visual_3d_mesh_hatch(GF_TraverseState *tr_state, GF_Mesh *mesh, u32 hatchStyle, SFColor hatchColor);
#endif
void visual_3d_draw_bbox(GF_TraverseState *tr_state, GF_BBox *box);
GF_Err visual_3d_init_autostereo(GF_VisualManager *visual);
void visual_3d_end_auto_stereo_pass(GF_VisualManager *visual);
void visual_3d_init_shaders(GF_VisualManager *visual);
void visual_3d_reset_graphics(GF_VisualManager *visual);
#endif
#endif