summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-12-10 18:31:20 +0200
committerCedric BAIL <cedric@osg.samsung.com>2014-12-23 21:20:20 +0100
commit61aab62be0e17fd58405debbc0f6befae66e64c8 (patch)
tree04b0b3ed39562f702fc0686a3e9d044ab5977579 /src/modules
parent17baa3fa6f87227fdba4caaea5e5c2a39257f5bb (diff)
evas: entry points to modules is Eina_File. Model_Common_Loader is deleted.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/evas/model_loaders/eet/evas_model_load_eet.c4
-rw-r--r--src/modules/evas/model_loaders/md2/evas_model_load_md2.c33
-rw-r--r--src/modules/evas/model_loaders/obj/evas_model_load_obj.c28
-rw-r--r--src/modules/evas/model_loaders/ply/evas_model_load_ply.c22
4 files changed, 64 insertions, 23 deletions
diff --git a/src/modules/evas/model_loaders/eet/evas_model_load_eet.c b/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
index 572e085..b393787 100644
--- a/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
+++ b/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
@@ -104,12 +104,12 @@ _set_material_to_mesh_from_eet_file(Evas_3D_Mesh *mesh,
104} 104}
105 105
106void 106void
107evas_model_load_file_eet(Evas_3D_Mesh *mesh, Model_Common_Loader *loader) 107evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file)
108{ 108{
109 Eet_File *ef; 109 Eet_File *ef;
110 110
111 _evas_3d_eet_file_init(); 111 _evas_3d_eet_file_init();
112 ef = eet_open(eina_file_filename_get(loader->file), EET_FILE_MODE_READ); 112 ef = eet_open(eina_file_filename_get(file), EET_FILE_MODE_READ);
113 eet_file = eet_data_read(ef, 113 eet_file = eet_data_read(ef,
114 _file_descriptor, 114 _file_descriptor,
115 EVAS_3D_FILE_CACHE_FILE_ENTRY); 115 EVAS_3D_FILE_CACHE_FILE_ENTRY);
diff --git a/src/modules/evas/model_loaders/md2/evas_model_load_md2.c b/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
index a7fddc7..98989ab 100644
--- a/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
+++ b/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
@@ -67,7 +67,7 @@ struct PACKED _MD2_Texcoord
67 67
68typedef struct _MD2_Loader 68typedef struct _MD2_Loader
69{ 69{
70 Model_Common_Loader *common_loader; 70 char *map;
71 int size; 71 int size;
72 72
73 int skin_width; 73 int skin_width;
@@ -252,21 +252,28 @@ static const float normal_table[162][3] =
252}; 252};
253 253
254static inline Eina_Bool 254static inline Eina_Bool
255_md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader) 255_md2_loader_init(MD2_Loader *loader, Eina_File *file)
256{ 256{
257 MD2_Header header; 257 MD2_Header header;
258 258
259 memset(loader, 0x00, sizeof(MD2_Loader)); 259 memset(loader, 0x00, sizeof(MD2_Loader));
260 loader->common_loader = common_loader; 260
261 loader->map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
262
263 if (loader->map == NULL)
264 {
265 ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
266 goto error;
267 }
261 268
262 /* Check file size. We require a file larger than MD2 header size. */ 269 /* Check file size. We require a file larger than MD2 header size. */
263 loader->size = eina_file_size_get(loader->common_loader->file); 270 loader->size = eina_file_size_get(file);
264 271
265 if (loader->size < (int)sizeof(MD2_Header)) 272 if (loader->size < (int)sizeof(MD2_Header))
266 goto error; 273 goto error;
267 274
268 /* Read header. */ 275 /* Read header. */
269 memcpy(&header, loader->common_loader->map, sizeof(MD2_Header)); 276 memcpy(&header, loader->map, sizeof(MD2_Header));
270 277
271 /* Check identity */ 278 /* Check identity */
272 if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION) 279 if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION)
@@ -296,14 +303,14 @@ _md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader)
296 303
297 loader->frame_count = header.frame_count; 304 loader->frame_count = header.frame_count;
298 loader->frame_size = header.frame_size; 305 loader->frame_size = header.frame_size;
299 loader->frames = loader->common_loader->map + header.offset_frames; 306 loader->frames = loader->map + header.offset_frames;
300 307
301 loader->vertex_count = header.vertex_count; 308 loader->vertex_count = header.vertex_count;
302 loader->triangle_count = header.triangle_count; 309 loader->triangle_count = header.triangle_count;
303 loader->texcoord_count = header.texcoord_count; 310 loader->texcoord_count = header.texcoord_count;
304 311
305 loader->triangles = (MD2_Triangle *)(loader->common_loader->map + header.offset_triangles); 312 loader->triangles = (MD2_Triangle *)(loader->map + header.offset_triangles);
306 loader->texcoords = (MD2_Texcoord *)(loader->common_loader->map + header.offset_texcoords); 313 loader->texcoords = (MD2_Texcoord *)(loader->map + header.offset_texcoords);
307 return EINA_TRUE; 314 return EINA_TRUE;
308 315
309error: 316error:
@@ -311,7 +318,7 @@ error:
311} 318}
312 319
313void 320void
314evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader) 321evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file)
315{ 322{
316 MD2_Loader loader; 323 MD2_Loader loader;
317 int i, j, k; 324 int i, j, k;
@@ -321,7 +328,7 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
321 Evas_3D_Mesh_Data *pd; 328 Evas_3D_Mesh_Data *pd;
322 329
323 /* Initialize MD2 loader (Open file and read MD2 head ant etc) */ 330 /* Initialize MD2 loader (Open file and read MD2 head ant etc) */
324 if (!_md2_loader_init(&loader, common_loader)) 331 if (!_md2_loader_init(&loader, file))
325 { 332 {
326 ERR("Failed to initialize MD2 loader."); 333 ERR("Failed to initialize MD2 loader.");
327 return; 334 return;
@@ -409,5 +416,11 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
409 ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f); 416 ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f);
410 } 417 }
411 } 418 }
419
420 if (loader.map)
421 {
422 eina_file_map_free(file, loader.map);
423 loader.map = NULL;
424 }
412} 425}
413 426
diff --git a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
index 7c6869e..64c4eb9 100644
--- a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
+++ b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
@@ -83,11 +83,11 @@ _analyze_face_line(char * face_analyzer,
83} 83}
84 84
85static inline OBJ_Counts 85static inline OBJ_Counts
86_count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj 86_count_elements(char *map)//count elements of mesh in .obj
87{ 87{
88 OBJ_Counts counts = _new_count_elements(); 88 OBJ_Counts counts = _new_count_elements();
89 89
90 char * current = loader->map; 90 char *current = map;
91 int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles 91 int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles
92 Eina_Bool will_check_next_char = EINA_FALSE; 92 Eina_Bool will_check_next_char = EINA_FALSE;
93 Eina_Bool first_char_is_v = EINA_FALSE; 93 Eina_Bool first_char_is_v = EINA_FALSE;
@@ -178,7 +178,7 @@ _count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj
178} 178}
179 179
180void 180void
181evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader) 181evas_model_load_file_obj(Evas_3D_Mesh *mesh, Eina_File *file)
182{ 182{
183 long i; 183 long i;
184 OBJ_Counts counts;//count elements of mesh in .obj 184 OBJ_Counts counts;//count elements of mesh in .obj
@@ -188,9 +188,17 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
188 float *pos, *nor, *tex; 188 float *pos, *nor, *tex;
189 int stride_pos, stride_nor, stride_tex; 189 int stride_pos, stride_nor, stride_tex;
190 int j, k; 190 int j, k;
191 char * current; 191 char *current, *map;
192 192
193 counts = _count_elements(loader); 193 map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
194
195 if (map == NULL)
196 {
197 ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
198 return;
199 }
200
201 counts = _count_elements(map);
194 202
195 float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float)); 203 float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float));
196 float *_normales_obj = malloc(counts._normal_counter * 3 * sizeof(float)); 204 float *_normales_obj = malloc(counts._normal_counter * 3 * sizeof(float));
@@ -198,7 +206,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
198 /* triangle has 3 points, every point has 3(vertix, texture and normal) coord */ 206 /* triangle has 3 points, every point has 3(vertix, texture and normal) coord */
199 int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int)); 207 int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int));
200 208
201 if ((loader->map == NULL) || (_vertices_obj == NULL) || 209 if ((map == NULL) || (_vertices_obj == NULL) ||
202 (_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL)) 210 (_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL))
203 { 211 {
204 ERR("Allocate memory is failed."); 212 ERR("Allocate memory is failed.");
@@ -209,7 +217,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
209 return; 217 return;
210 } 218 }
211 219
212 current = loader->map; 220 current = map;
213 i = 0; 221 i = 0;
214 222
215 /* put data to arrays */ 223 /* put data to arrays */
@@ -373,5 +381,11 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
373 { 381 {
374 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0); 382 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
375 } 383 }
384
385 if (map)
386 {
387 eina_file_map_free(file, map);
388 map = NULL;
389 }
376} 390}
377 391
diff --git a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
index 246f7cd..0eac908 100644
--- a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
+++ b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
@@ -178,19 +178,27 @@ _read_header(char *map)//Check properties of mesh in .ply file.
178} 178}
179 179
180void 180void
181evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader) 181evas_model_load_file_ply(Evas_3D_Mesh *mesh, Eina_File *file)
182{ 182{
183 Evas_3D_Mesh_Data *pd; 183 Evas_3D_Mesh_Data *pd;
184 int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0; 184 int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0;
185 float *pos, *nor, *tex, *col; 185 float *pos, *nor, *tex, *col;
186 int stride_pos, stride_nor, stride_tex, stride_col; 186 int stride_pos, stride_nor, stride_tex, stride_col;
187 char *current; 187 char *current, *map;
188 PLY_Header header; 188 PLY_Header header;
189 float *_vertices_ply = NULL, *_normals_ply = NULL; 189 float *_vertices_ply = NULL, *_normals_ply = NULL;
190 float *_tex_coords_ply = NULL, *_colors_ply = NULL; 190 float *_tex_coords_ply = NULL, *_colors_ply = NULL;
191 char **helping_pointer; 191 char **helping_pointer;
192 192
193 header = _read_header(loader->map); 193 map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
194
195 if (map == NULL)
196 {
197 ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
198 return;
199 }
200
201 header = _read_header(map);
194 202
195 if (!header.existence_of_geometries) 203 if (!header.existence_of_geometries)
196 { 204 {
@@ -198,7 +206,7 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
198 return; 206 return;
199 } 207 }
200 208
201 helping_pointer = eina_str_split(loader->map, "end_header\n", 0); 209 helping_pointer = eina_str_split(map, "end_header\n", 0);
202 210
203 if (helping_pointer == NULL) 211 if (helping_pointer == NULL)
204 { 212 {
@@ -369,5 +377,11 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
369 { 377 {
370 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0); 378 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
371 } 379 }
380
381 if (map)
382 {
383 eina_file_map_free(file, map);
384 map = NULL;
385 }
372} 386}
373 387