[Plib-devel] ssgLoad3ds portability
Brought to you by:
sjbaker
From: Troy Y. <tro...@ho...> - 2000-08-11 06:47:24
|
I suppose that this is probably of most interest to Dave but there may be others of you that are potentially coding yourselves into the same boat. I managed to get the SG and SSG libraries compiled on HPUX 10.20 on a C180 class workstation. The HP is *very* particular about having certain things start on word boundaries. I had to make the following changes to ssgLoad3ds.cxx to get it to run without coring and to correctly load a model. These particular changes were made to the version of this file distributed in plib 1.1.11 - I don't know if additional changes are necessary for the most recent version. Most of the changes relate to how get() is used. Instead of passing a pointer that might not be on a word boundary to get(), data is copied from the input buffer into a local temporary variable of the correct type and the address of that variable is passed to get(). Rather than list every change, I'll give an example and a list of functions effected. Original: static int parse_uscale( char **p, unsigned long length ) { texture_scale[ num_materials - 1 ][0] = get((float*)*p); return PARSE_OK; } Becomes: static int parse_uscale( char **p, unsigned long length ) { float lTmpFloat; memcpy((void *) &lTmpFloat, (void *) *p, sizeof(float)); texture_scale[ num_materials - 1 ][0] = get(&lTmpFloat); return PARSE_OK; } Other functions effected: parse_vscale(): 1 instance (line 261) parse_uoffst(): 1 instance (line 267) parse_voffst(): 1 instance (line 273) parse_rgb1(): 3 instances (line 305, 306, 307) parse_shininess(): 1 instance (line 348) parse_transparency(): 1 instance (line 356) parse_vert_list(): 4 instances (line 422, 428, 429, 430) parse_smooth_list(): 1 instance (line 445) parse_face_list(): 7 instances (line 504, 515 - 518, 541, 542) parse_map_list(): 3 instances (line 565, 571, 572) parse_face_materials(): 2 instances (line 628, 653) parse_chunks(): 2 instances (line 732, 733) There are several casts that must be modified. (line 423, 440, 503, 566, 627) I also had to fix a small problem with one of the get() functions. Original: static float get(float *f) { if (is_little_endian) return *f; else { unsigned long p = (unsigned long)*f; endian_swap(&p); return p; } } Fixed: static float get(float *f) { if (is_little_endian) return *f; else { float lTmpFloat = *f; endian_swap((unsigned long *) &lTmpFloat); return lTmpFloat; } } After all that, I've also attached the file with my mods and an output of diff. Let me know if you need anything else. Troy. |