Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 4, 2006, 3:06:00 PM (18 years ago)
Author:
bensch
Message:

merged back

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/lib/graphics/importer/md2/md2Model.cc

    r9003 r9140  
    1717#include "md2Model.h"
    1818#include "material.h"
    19 
     19#include "config.h"
     20#ifdef HAVE_SDL_SDL_H
     21#include <SDL/SDL.h>
     22#include <SDL/SDL_endian.h>
     23#else
     24#include <SDL.h>
     25#include <SDL_endian.h>
     26#endif
    2027#include "debug.h"
    2128#include "util/loading/resource_manager.h"
     
    6673  };
    6774
    68 
     75#ifdef SDL_LIL_ENDIAN
     76#define BULK_CONV( _ptr, _num ) do { \
     77        int  _cnt = _num;\
     78        int* _iptr = (int*)_ptr;\
     79        for( int _l = 0; _l<_cnt; ++_l )\
     80                _iptr[_l] = SDL_SwapLE32( _iptr[_l] );\
     81} while( 0 )
     82#define BULK_CONV16( _ptr, _num ) do { \
     83        short  _cnt = _num;\
     84        short* _iptr = (short*)_ptr;\
     85        for( int _l = 0; _l<_cnt; ++_l )\
     86                _iptr[_l] = SDL_SwapLE16( _iptr[_l] );\
     87} while( 0 )
     88#else
     89#define BULK_CONV( _ptr, _num )
     90#define BULK_CONV16( _ptr, _num )
     91#endif
    6992
    7093/********************************************************************************
     
    467490  this->header = new MD2Header;
    468491  fread(this->header, 1, sizeof(MD2Header), pFile);
     492        BULK_CONV( this->header, sizeof(MD2Header)/4 );
    469493  /* check for the header version: make sure its a md2 file :) */
    470   if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
     494  if( unlikely( this->header->version != MD2_VERSION) && unlikely( this->header->ident != MD2_IDENT))
    471495    {
    472496      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
     
    474498    }
    475499
    476   this->fileName =fileName;
     500  this->fileName = fileName;
    477501  /* got the data: map it to locals */
    478502  this->numFrames = this->header->numFrames;
     
    493517  fseek(pFile, this->header->offsetFrames, SEEK_SET);
    494518  fread(buffer, this->header->frameSize, this->numFrames, pFile);
     519        //BULK_CONV( buffer, this->header->frameSize*this->numFrames*sizeof(char)/4 );
    495520  /* read opengl commands */
    496521  fseek(pFile, this->header->offsetGlCommands, SEEK_SET);
     522
    497523  fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile);
     524        BULK_CONV( this->pGLCommands, this->numGLCommands );
    498525  /* triangle list */
    499526  fseek(pFile, this->header->offsetTriangles, SEEK_SET);
    500   fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);
     527  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);       
     528        BULK_CONV16( this->pTriangles, this->numTriangles*sizeof(sTriangle)/2 );
     529
    501530  /*  read in texture coordinates */
    502531  fseek(pFile, this->header->offsetTexCoords, SEEK_SET);
    503532  fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile);
    504 
     533        BULK_CONV16( this->pTexCoor, this->numTexCoor*sizeof(sTexCoor)/2 );
    505534
    506535  for(int i = 0; i < this->numFrames; ++i)
    507536    {
    508537      frame = (sFrame*)(buffer + this->header->frameSize * i);
     538                        //Convert the translate and scale Vec3D if needed.
     539                        BULK_CONV( frame, 6 );
     540                        BULK_CONV( frame->pVertices, 3 );
    509541      pVertex = this->pVertices + this->numVertices  * i;
    510542      pNormals = this->pLightNormals + this->numVertices * i;
Note: See TracChangeset for help on using the changeset viewer.