1 /* 2 * GPAC - Multimedia Framework C SDK 3 * 4 * Authors: Jean Le Feuvre 5 * Copyright (c) Telecom ParisTech 2000-2012 6 * All rights reserved 7 * 8 * This file is part of GPAC / Scene Compositor sub-project 9 * 10 * GPAC is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2, or (at your option) 13 * any later version. 14 * 15 * GPAC is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; see the file COPYING. If not, write to 22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 */ 25 26 #ifndef _VISUAL_MANAGER_H_ 27 #define _VISUAL_MANAGER_H_ 28 29 #include "drawable.h" 30 31 /*all 2D related functions and macro are locate there*/ 32 #include "visual_manager_2d.h" 33 34 /*all 3D related functions and macro are locate there*/ 35 #include "visual_manager_3d.h" 36 37 38 //startof GL3/ES2.0 specifics 39 40 /* number of preprocessor flags for GL3/ES2.0 */ 41 #define GF_GL_NUM_OF_FLAGS 6 42 #ifdef GPAC_CONFIG_ANDROID 43 #define GF_GL_NB_FRAG_SHADERS (1<<(GF_GL_NUM_OF_FLAGS) ) //=2^GF_GL_NUM_OF_FLAGS 44 #else 45 #define GF_GL_NB_FRAG_SHADERS (1<<(GF_GL_NUM_OF_FLAGS-1) ) //=2^GF_GL_NUM_OF_FLAGS-1 ( ExternalOES ignored in fragment shader when the platform is not Android) 46 #endif // GPAC_CONFIG_ANDROID 47 #define GF_GL_NB_VERT_SHADERS (1<<(GF_GL_NUM_OF_FLAGS-2) ) //=2^GF_GL_NUM_OF_FLAGS-2 (YUV and ExternalOES ignored in vertex shader) 48 49 /* setting preprocessor flags for GL3/ES2.0 shaders */ 50 enum { 51 GF_GL_HAS_TEXTURE = 1, 52 GF_GL_HAS_LIGHT = (1<<1), 53 GF_GL_HAS_COLOR = (1<<2), 54 GF_GL_HAS_CLIP = (1<<3), 55 //only for fragment shaders 56 GF_GL_IS_YUV = (1<<4), 57 GF_GL_IS_ExternalOES = (1<<5), 58 }; 59 //endof 60 61 enum 62 { 63 GF_3D_CAMERA_STRAIGHT = 0, 64 GF_3D_CAMERA_OFFAXIS, 65 GF_3D_CAMERA_LINEAR, 66 GF_3D_CAMERA_CIRCULAR, 67 }; 68 69 70 #ifndef GPAC_DISABLE_3D 71 72 #if defined( _LP64 ) && defined(CONFIG_DARWIN_GL) 73 #define GF_SHADERID u64 74 #else 75 #define GF_SHADERID u32 76 #endif 77 78 typedef struct _gl_prog 79 { 80 GF_SHADERID vertex; 81 GF_SHADERID fragment; 82 GF_SHADERID prog; 83 u32 flags; 84 u32 pix_fmt; 85 } GF_GLProgInstance; 86 #endif 87 88 89 struct _visual_manager 90 { 91 GF_Compositor *compositor; 92 Bool direct_flush; 93 94 #ifndef GPAC_DISABLE_3D 95 /*3D type for the visual: 96 0: visual is 2D 97 1: visual is 2D with 3D acceleration (2D camera) 98 2: visual is 3D MPEG-4 (with 3D camera) 99 3: visual is 3D X3D (with 3D camera) 100 */ 101 u32 type_3d; 102 #endif 103 104 #ifndef GPAC_DISABLE_VRML 105 /*background stack*/ 106 GF_List *back_stack; 107 /*viewport stack*/ 108 GF_List *view_stack; 109 #endif 110 111 112 /*size in pixels*/ 113 u32 width, height; 114 115 /* 116 * Visual Manager part for 2D drawing and dirty rect 117 */ 118 119 /*the one and only dirty rect collector for this visual manager*/ 120 GF_RectArray to_redraw; 121 u32 draw_node_index; 122 123 /*display list (list of drawable context). The first context with no drawable attached to 124 it (ctx->drawable==NULL) marks the end of the display list*/ 125 DrawableContext *context, *cur_context; 126 127 /*keeps track of nodes drawn last frame*/ 128 struct _drawable_store *prev_nodes, *last_prev_entry; 129 130 /*pixel area in BIFS coords - eg area to fill with background*/ 131 GF_IRect surf_rect; 132 /*top clipper (may be different than surf_rect when a viewport is active)*/ 133 GF_IRect top_clipper; 134 135 u32 last_had_back; 136 137 /*signals that the hardware surface is attached to buffer/device/stencil*/ 138 Bool is_attached; 139 Bool center_coords; 140 Bool has_modif; 141 Bool has_overlays; 142 Bool has_text_edit; 143 144 /*gets access to graphics handle (either OS-specific or raw memory)*/ 145 GF_Err (*GetSurfaceAccess)(GF_VisualManager *); 146 /*release graphics handle*/ 147 void (*ReleaseSurfaceAccess)(GF_VisualManager *); 148 149 /*clear given rect or all visual if no rect specified - clear color depends on visual's type: 150 BackColor for background nodes 151 0x00000000 for composite, 152 compositor clear color otherwise 153 offscreen_clear is set to 1 when the clear targets the entire canvas buffer in hybrid GL mode (full redraw) 154 to 2 when the clear targets a part of the canvas buffer in hybrid GL mode (dirty area clean) 155 */ 156 void (*ClearSurface)(GF_VisualManager *visual, GF_IRect *rc, u32 BackColor, u32 offscreen_clear); 157 /*draws specified texture as flat bitmap*/ 158 Bool (*DrawBitmap)(GF_VisualManager *visual, GF_TraverseState *tr_state, DrawableContext *ctx); 159 /*checks if the visual is ready for being drawn on. Returns GF_FALSE if no draw operation can be sent*/ 160 Bool (*CheckAttached)(GF_VisualManager *visual); 161 162 /*raster surface interface*/ 163 GF_EVGSurface *raster_surface; 164 /*raster brush interface*/ 165 GF_EVGStencil *raster_brush; 166 167 /*node owning this visual manager (composite textures) - NULL for root visual*/ 168 GF_Node *offscreen; 169 170 /*value of the flag to use to signal any geometry changes*/ 171 u32 bounds_tracker_modif_flag; 172 173 u32 num_nodes_prev_frame, num_nodes_current_frame; 174 175 /*list of video overlays sorted from first to last*/ 176 struct _video_overlay *overlays; 177 178 #ifndef GPAC_DISABLE_3D 179 /* 180 * Visual Manager part for 3D drawing 181 */ 182 183 #ifndef GPAC_DISABLE_VRML 184 /*navigation stack*/ 185 GF_List *navigation_stack; 186 /*fog stack*/ 187 GF_List *fog_stack; 188 #endif 189 190 Bool gl_setup; 191 192 GF_IRect clipper_2d; 193 Bool has_clipper_2d; 194 /*the one and only camera associated with the visual*/ 195 GF_Camera camera; 196 197 /*list of transparent nodes to draw after TRAVERSE_SORT pass*/ 198 GF_List *alpha_nodes_to_draw; 199 200 /*lighting stuff*/ 201 u32 num_lights; 202 u32 max_lights; 203 /*cliping stuff*/ 204 u32 num_clips; 205 u32 max_clips; 206 207 //when using 2D layering in opengl, we store the bounding rect of drawn objects betwwen GL calls, so we 208 //can flush only the minimum part of the texture 209 GF_RectArray hybgl_drawn; 210 u32 nb_objects_on_canvas_since_last_ogl_flush; 211 212 u32 nb_views, current_view, autostereo_type, camlay; 213 214 GF_SHADERID base_glsl_vertex; 215 216 u32 *gl_textures; 217 u32 auto_stereo_width, auto_stereo_height; 218 GF_Mesh *autostereo_mesh; 219 GF_SHADERID autostereo_glsl_program; 220 GF_SHADERID autostereo_glsl_fragment; 221 222 Bool needs_projection_matrix_reload; 223 224 /*GL state to emulate with GLSL [ES2.0]*/ 225 Bool has_material_2d; 226 SFColorRGBA mat_2d; 227 228 Bool has_material; 229 SFColorRGBA materials[4]; 230 Fixed shininess; 231 232 Bool state_light_on, state_blend_on, state_color_on; 233 234 GF_ClipInfo clippers[GF_MAX_GL_CLIPS]; 235 236 Bool has_tx_matrix; 237 GF_Matrix tx_matrix; 238 239 GF_LightInfo lights[GF_MAX_GL_LIGHTS]; 240 Bool has_inactive_lights; 241 242 Bool has_fog; 243 u32 fog_type; 244 SFColor fog_color; 245 Fixed fog_density, fog_visibility; 246 247 /*end of GL state to emulate with GLSL*/ 248 249 /* shaders used for shader-only drawing */ 250 GF_SHADERID glsl_program; 251 GF_List *compiled_programs; 252 u32 bound_tx_pix_fmt; //only one texture currently supported 253 254 u32 active_glsl_flags; 255 #endif //!GPAC_DISABLE_3D 256 257 #ifdef GF_SR_USE_DEPTH 258 Fixed depth_vp_position, depth_vp_range; 259 #endif 260 261 u32 yuv_pixelformat_type; 262 }; 263 264 /*constructor/destructor*/ 265 GF_VisualManager *visual_new(GF_Compositor *compositor); 266 void visual_del(GF_VisualManager *visual); 267 268 /*draw cycle for the visual*/ 269 Bool visual_draw_frame(GF_VisualManager *visual, GF_Node *root, GF_TraverseState *tr_state, Bool is_root_visual); 270 271 /*executes scene event (picks node if needed) - returns FALSE if no scene event handler has been called*/ 272 Bool visual_execute_event(GF_VisualManager *visual, GF_TraverseState *tr_state, GF_Event *ev, GF_ChildNodeItem *children); 273 274 Bool visual_get_size_info(GF_TraverseState *tr_state, Fixed *surf_width, Fixed *surf_height); 275 276 /*reset all appearance dirty state and visual registration info*/ 277 void visual_clean_contexts(GF_VisualManager *visual); 278 279 280 void visual_reset_graphics(GF_VisualManager *visual); 281 282 #ifndef GPAC_DISABLE_3D 283 GF_GLProgInstance *visual_3d_check_program_exists(GF_VisualManager *root_visual, u32 flags, u32 pix_fmt); 284 #endif 285 286 #endif /*_VISUAL_MANAGER_H_*/ 287 288