Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NBF.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #pragma once
00013 
00015 #include "nvsgcommon.h"
00016 
00017 // NBF is independent of packing. However, this forces
00018 // the compile-time asserts below to fire on inconsistencies
00019 #pragma pack(push, 1)
00020 
00021 // convenient aliases for used built-in types
00022 typedef char                    byte_t;   
00023 typedef unsigned char           ubyte_t;  
00024 typedef int                     int_t;    
00025 typedef unsigned int            uint_t;   
00026 typedef unsigned long long      uint64_t; 
00027 typedef float                   float2_t[2]; 
00028 typedef float                   float3_t[3]; 
00029 typedef float                   float4_t[4]; 
00030 
00031 // convenient macro to add padding bits
00032 #define PADDING(n) PADDING_i(n,__LINE__) 
00033 #define PADDING_i(n,l) PADDING_ii(n,l)
00034 #define PADDING_ii(n,l) ubyte_t padding##l[n] 
00035 
00036 // NBF version
00037 const ubyte_t NBF_VER_MAJOR  =  0x04; 
00038 const ubyte_t NBF_VER_MINOR  =  0x01; 
00039 const ubyte_t NBF_VER_BUGFIX =  0x00; 
00040   
00041 // constants specifying a certain byte order
00042 const ubyte_t NBF_LITTLE_ENDIAN = 0x00; 
00043 const ubyte_t NBF_BIG_ENDIAN =  0x01;   
00044 
00045 // convenient helper types
00046 
00048 struct str_t 
00049 { 
00050   uint_t      numChars;           
00051 
00052   uint_t      chars;              
00053 };
00054 __CTASSERT(sizeof(str_t)%4==0);
00055 
00057 
00058 struct texCoordSet_t 
00059 {
00060   uint_t      numTexCoords;       
00061   uint_t      coordDim;           
00062 
00063   uint_t      texCoords;          
00064 };
00065 __CTASSERT(sizeof(texCoordSet_t)%4==0);
00066 
00068 
00069 struct geometrySet_t
00070 {
00071   uint_t      drawable;           
00072   uint_t      stateSet;           
00073 };
00074 __CTASSERT(sizeof(geometrySet_t)%4==0);
00075 
00077 
00078 struct indexSet_t
00079 {
00080   uint_t      numIndices;         
00081   uint_t      indices;            
00082 
00083 };
00084 __CTASSERT(sizeof(indexSet_t)%4==0);
00085 
00087 
00089 struct texBinding_t
00090 {
00091   uint_t      texUnit;            
00092   uint_t      texAttribItem;      
00093 };
00094 __CTASSERT(sizeof(texBinding_t)%4==0);
00095 
00097 struct trafo_t
00098 {
00099   float4_t    orientation;        
00100   float3_t    scaling;            
00101   float3_t    translation;        
00102   float3_t    center;             
00103 };
00104 __CTASSERT(sizeof(trafo_t)%4==0);
00105 
00107 
00108 struct tweak_t
00109 {
00110   str_t       name;               
00111   uint_t      type;               
00112   union
00113   {
00114     uint_t      value;            
00115 
00116     str_t       strval;           
00117 
00118   }; 
00119 };
00120 __CTASSERT(sizeof(tweak_t)%4==0);
00121 
00123 
00124 struct bone_t
00125 {
00126   float       weight;             
00127 
00128   uint_t      animation;          
00129 
00130 };
00131 __CTASSERT(sizeof(bone_t)%4==0);
00132 
00134 
00135 struct skin_t
00136 {
00137   uint_t      numBones;           
00138   uint_t      bones;              
00139 
00140   float3_t    vertex;             
00141   float3_t    normal;             
00142 };
00143 __CTASSERT(sizeof(skin_t)%4==0);
00144 
00146 
00150 enum
00151 {
00152   // scene object 
00153   NBF_UNKNOWN                     = 0x00000000  
00154   // animation objects (0x100 - 0x1FF)
00155 , NBF_TRAFO_ANIMATION           = 0x00000100
00156 , NBF_VNVECTOR_ANIMATION
00157   // framed animations
00158 , NBF_FRAMED_ANIMATION          = 0x00000120
00159 , NBF_FRAMED_TRAFO_ANIMATION                  
00160 , NBF_FRAMED_VNVECTOR_ANIMATION               
00161   // interpolated animations 
00162 , NBF_INTERPOLATED_ANIMATION    = 0x00000140
00163 , NBF_LINEAR_INTERPOLATED_TRAFO_ANIMATION     
00164 , NBF_LINEAR_INTERPOLATED_VNVECTOR_ANIMATION  
00165   // camera objects (0x200 - 0x2FF)
00166 , NBF_CAMERA                    = 0x00000200
00167 , NBF_MONO_CAMERA
00168 , NBF_JITTER_CAMERA
00169 , NBF_SIMPLE_CAMERA
00170 , NBF_PARALLEL_CAMERA                         
00171 , NBF_PERSPECTIVE_CAMERA                      
00172 , NBF_STEREO_CAMERA  
00173   // drawable objects (0x300 - 0x3FF) 
00174 , NBF_DRAWABLE                  = 0x00000300
00175 , NBF_GEO_SET
00176 , NBF_TRIANGLES                               
00177 , NBF_ANIMATED_TRIANGLES                      
00178 , NBF_SKINNED_TRIANGLES                       
00179 , NBF_TRISTRIPS                               
00180 , NBF_QUADS                                   
00181 , NBF_ANIMATED_QUADS                          
00182 , NBF_QUADSTRIPS                              
00183   // node objects (0x400 - 0x4FF)
00184 , NBF_NODE                      = 0x00000400
00185 , NBF_GEO_NODE                                
00186 , NBF_GROUP                                   
00187 , NBF_LOD                                     
00188 , NBF_SWITCH                                  
00189 , NBF_TRANSFORM                               
00190 , NBF_ANIMATED_TRANSFORM                      
00191 , NBF_LIGHT_SOURCE
00192 , NBF_DIRECTED_LIGHT                          
00193 , NBF_POINT_LIGHT                             
00194 , NBF_SPOT_LIGHT                              
00195   // state set objects (0x500 - 0x5FF)
00196 , NBF_STATE_SET                 = 0x00000500  
00197   // state attribute objects (0x600 - 0x6FF)
00198 , NBF_STATE_ATTRIBUTE           = 0x00000600
00199 , NBF_CGFX                                    
00200 , NBF_MATERIAL                                
00201 , NBF_FACE_ATTRIBUTE                          
00202 , NBF_TEXTURE_ATTRIBUTE                       
00203 , NBF_TEXTURE_ATTRIBUTE_ITEM                  
00204   // custom objects (>=0x700)
00205 , NBF_CUSTOM_OBJECT                           
00206 };
00207 
00209 
00215 struct NBFHeader
00216 {
00217   // signature
00218   byte_t      signature[4];       
00219   // NBF version
00220   ubyte_t     nbfMajorVersion;    
00221   ubyte_t     nbfMinorVersion;    
00222   ubyte_t     nbfBugfixLevel;     
00223 
00224 
00225   // NVSG version
00226   ubyte_t     nvsgMajorVersion;   
00227   ubyte_t     nvsgMinorVersion;   
00228   ubyte_t     nvsgBugfixLevel;    
00229 
00230 
00231   // Reserved bytes 
00232   ubyte_t     reserved[16];       
00233   // Date
00234   ubyte_t     dayLastModified;    
00235   ubyte_t     monthLastModified;  
00236   ubyte_t     yearLastModified[2]; 
00237   // Time stamp
00238   ubyte_t     secondLastModified; 
00239   ubyte_t     minuteLastModified; 
00240   ubyte_t     hourLastModified;   
00241   // endianess
00242   ubyte_t     byteOrder;          
00243 
00244 
00245   PADDING(2);                     
00246   // scene object
00247   uint_t      scene;              
00248   // optional view state
00249   uint_t      viewState;          
00250 
00251 };
00252 __CTASSERT(sizeof(NBFHeader)%4==0);
00253 
00255 
00257 struct NBFScene
00258 {
00259   float3_t    backColor;                
00260   uint_t      numCameras;               
00261   uint_t      cameras;                  
00262   uint_t      numCameraAnimations;      
00263   uint_t      cameraAnimations;         
00264   uint_t      defaultStateSet;          
00265   uint_t      overrideStateSet;         
00266   uint_t      numberOfAnimationFrames;  
00267   uint_t      root;                     
00268 };
00269 __CTASSERT(sizeof(NBFScene)%4==0);
00270 
00272 
00273 struct NBFViewState
00274 {
00275   uint_t      objectCode;         
00276   uint_t      camera;             
00277 };
00278 __CTASSERT(sizeof(NBFViewState)%4==0);
00279 
00281 struct NBFObject
00282 {
00283   uint_t      objectCode;         
00284   ubyte_t     isShared;           
00285 
00286 
00287   PADDING(3);                     
00288   uint64_t    objectDataID;       
00289   uint_t      sourceObject;       
00290 
00291   str_t       objectName;         
00292   // NOTE: Because of the uint64_t member objectDataID above, which is 8-byte aligned, 
00293   // we need to ensure the size of NBFObject is fixed - that is, independent of whatever
00294   // the compilers actual packing value might be! We achieve this by making the size of 
00295   // NBFObject a multiple of 8 bytes (see compile time assert below).  
00296   PADDING(4);                     
00297 };
00298 __CTASSERT(sizeof(NBFObject)%8==0);
00299 
00301 
00306 struct NBFTrafoAnimation : public NBFObject
00307 {
00308   uint_t      trafos;             
00309 
00310 
00311   PADDING(4);        
00312 };
00313 __CTASSERT(sizeof(NBFTrafoAnimation)%8==0);
00314 
00316 
00321 struct NBFVNVectorAnimation : public NBFObject
00322 {
00323   uint_t      numVertices;        
00324 
00325   uint_t      vertexSets;         
00326 
00327 
00328 
00329 
00330   uint_t      numNormals;         
00331 
00332   uint_t      normalSets;         
00333 
00334 
00335 
00336 
00337                                   
00338 };
00339 __CTASSERT(sizeof(NBFVNVectorAnimation)%8==0);
00340 
00342 
00347 struct NBFFramedAnimation
00348 {
00349   uint_t      numFrames;          
00350 
00351 
00352 
00353 
00354 };
00355 __CTASSERT(sizeof(NBFFramedAnimation)%4==0);
00356 
00358 
00360 struct NBFFramedTrafoAnimation : public NBFTrafoAnimation
00361                                , public NBFFramedAnimation
00362 {
00363   PADDING(4);         
00364 };
00365 __CTASSERT(sizeof(NBFFramedTrafoAnimation)%8==0);
00366 
00368 
00370 struct NBFFramedVNVectorAnimation : public NBFVNVectorAnimation
00371                                   , public NBFFramedAnimation
00372 {
00373   PADDING(4);         
00374 };
00375 __CTASSERT(sizeof(NBFFramedVNVectorAnimation)%8==0);
00376 
00378 
00383 struct NBFInterpolatedAnimation
00384 {
00385   uint_t      numKeys;            
00386   uint_t      keys;               
00387 
00388 };
00389 __CTASSERT(sizeof(NBFInterpolatedAnimation)%4==0);
00390 
00392 
00396 struct NBFInterpolatedTrafoAnimation : public NBFTrafoAnimation
00397                                      , public NBFInterpolatedAnimation
00398 {
00399 };
00400 __CTASSERT(sizeof(NBFInterpolatedTrafoAnimation)%8==0);
00401 
00403 
00407 struct NBFInterpolatedVNVectorAnimation : public NBFVNVectorAnimation
00408                                         , public NBFInterpolatedAnimation
00409 {
00410 };
00411 __CTASSERT(sizeof(NBFInterpolatedVNVectorAnimation)%8==0);
00412 
00414 
00415 struct NBFCamera : public NBFObject
00416 {
00417 };
00418 __CTASSERT(sizeof(NBFCamera)%8==0);
00419 
00421 
00422 struct NBFMonoCamera : public NBFCamera
00423 {
00424 };
00425 __CTASSERT(sizeof(NBFMonoCamera)%8==0);
00426 
00428 
00429 struct NBFJitterCamera : public NBFMonoCamera
00430 {
00431 };
00432 __CTASSERT(sizeof(NBFJitterCamera)%8==0);
00433 
00435 
00439 struct NBFSimpleCamera : public NBFMonoCamera
00440 {
00441   uint_t      numHeadLights;    
00442   uint_t      headLights;       
00443 
00444   float3_t    upVector;         
00445   float3_t    position;         
00446   float3_t    direction;        
00447   float       farDist;          
00448   float       nearDist;         
00449   float       targDist;         
00450   float       projectionDx;     
00451   ubyte_t     isAutoClipPlanes; 
00452   PADDING(3);      
00453   float2_t    windowSize;       
00454 
00455   float2_t    windowOffset;     
00456 
00457 };
00458 __CTASSERT(sizeof(NBFSimpleCamera)%8==0);
00459 
00461 
00463 struct NBFParallelCamera : public NBFSimpleCamera
00464 {
00465 };
00466 __CTASSERT(sizeof(NBFParallelCamera)%8==0);
00467 
00469 
00471 struct NBFPerspectiveCamera : public NBFSimpleCamera
00472 {
00473 };
00474 __CTASSERT(sizeof(NBFPerspectiveCamera)%8==0);
00475 
00477 
00478 struct NBFStereoCamera : public NBFCamera
00479 {
00480 };
00481 __CTASSERT(sizeof(NBFStereoCamera)%8==0);
00482 
00484 
00488 struct NBFDrawable : public NBFObject
00489 {
00490 };
00491 __CTASSERT(sizeof(NBFDrawable)%8==0);
00492 
00494 
00496 struct NBFGeoSet : public NBFDrawable
00497 {
00498   uint_t      numVertices;        
00499   uint_t      vertices;           
00500   uint_t      numNormals;         
00501   uint_t      normals;            
00502   uint_t      numTexCoordsSets;   
00503   uint_t      texCoordsSets;      
00504 
00505   uint_t      numColors;          
00506   uint_t      colorDim;           
00507 
00508   uint_t      colors;             
00509 
00510   uint_t      numSecondaryColors; 
00511   uint_t      secondaryColorDim;  
00512 
00513   uint_t      secondaryColors;    
00514 
00515   uint_t      numFogCoords;       
00516   uint_t      fogCoords;          
00517 
00518 };
00519 __CTASSERT(sizeof(NBFGeoSet)%8==0);
00520 
00522 
00524 struct NBFTriangles : public NBFGeoSet
00525 {
00526   uint_t      numFaces;           
00527   uint_t      faces;              
00528 
00529 };
00530 __CTASSERT(sizeof(NBFTriangles)%8==0);
00531 
00533 
00535 struct NBFAnimatedTriangles : public NBFTriangles
00536 {
00537   uint_t      animation;          
00538 
00539   PADDING(4);        
00540 };
00541 __CTASSERT(sizeof(NBFAnimatedTriangles)%8==0);
00542 
00544 
00546 struct NBFSkinnedTriangles : public NBFTriangles
00547 {
00548   uint_t      numSkins;           
00549   uint_t      skins;              
00550 };
00551 __CTASSERT(sizeof(NBFSkinnedTriangles)%8==0);
00552 
00554 
00556 struct NBFStrips : public NBFGeoSet
00557 {
00558   uint_t      numStrips;          
00559   uint_t      strips;             
00560 
00561 };
00562 __CTASSERT(sizeof(NBFStrips)%8==0);
00563 
00565 
00567 struct NBFQuads : public NBFGeoSet
00568 {
00569   uint_t      numFaces;           
00570   uint_t      faces;              
00571 
00572 };
00573 __CTASSERT(sizeof(NBFQuads)%8==0);
00574 
00576 
00578 struct NBFAnimatedQuads : public NBFQuads
00579 {
00580   uint_t      animation;          
00581 
00582   PADDING(4);        
00583 };
00584 __CTASSERT(sizeof(NBFAnimatedQuads)%8==0);
00585 
00587 
00591 struct NBFNode : public NBFObject
00592 {
00593   str_t       annotation;         //<! Specifies an optional annotation string.   
00594 };
00595 __CTASSERT(sizeof(NBFNode)%8==0);
00596 
00598 
00599 struct NBFGeoNode : public NBFNode
00600 {
00601   uint_t      numGeometrySets;    //<! Specifies the number of contained geometry sets.
00602   uint_t      geometrySets;       //<! Specifies the file offset to the geometry sets.
00603                                   //<! Geometry sets are stored as geometrySet_t objects.
00604 };
00605 __CTASSERT(sizeof(NBFGeoNode)%8==0);
00606 
00608 
00611 struct NBFGroup : public NBFNode
00612 {
00613   uint_t      numChildren;        
00614   uint_t      children;           
00615 
00616 };
00617 __CTASSERT(sizeof(NBFGroup)%8==0);
00618 
00620 
00621 struct NBFLOD : public NBFGroup
00622 {
00623   float3_t    center;             
00624   uint_t      numRanges;          
00625   uint_t      ranges;             
00626 
00627   PADDING(4);        
00628 };
00629 __CTASSERT(sizeof(NBFLOD)%8==0);
00630 
00632 
00633 struct NBFSwitch : public NBFGroup
00634 {
00635   uint_t      numActiveChildren;  
00636   uint_t      activeChildren;     
00637 
00638 };
00639 __CTASSERT(sizeof(NBFSwitch)%8==0);
00640 
00642 
00643 struct NBFTransform : public NBFGroup
00644 {
00645   trafo_t             trafo;
00646   PADDING(4);        
00647 };
00648 __CTASSERT(sizeof(NBFTransform)%8==0);
00649 
00651 
00652 struct NBFAnimatedTransform : public NBFTransform
00653 {
00654   uint_t      animation;          
00655 
00656   PADDING(4);        
00657 };
00658 __CTASSERT(sizeof(NBFAnimatedTransform)%8==0);
00659 
00661 
00663 struct NBFLightSource : public NBFNode
00664 {
00665   float       intensity;          
00666   float3_t    ambientColor;       
00667   float3_t    diffuseColor;       
00668   float3_t    specularColor;      
00669   trafo_t     trafo;              
00670   uint_t      animation;          
00671 
00672 };
00673 __CTASSERT(sizeof(NBFLightSource)%8==0);
00674 
00675 // The NBFDirectedLight structure represents a directed light source.
00677 struct NBFDirectedLight : public NBFLightSource
00678 {
00679 };
00680 __CTASSERT(sizeof(NBFDirectedLight)%8==0);
00681 
00682 // The NBFPointLight structure represents a point light source.
00684 struct NBFPointLight : public NBFLightSource
00685 {
00686   float3_t    attenuation;        
00687 
00688 
00689 
00690   PADDING(4);        
00691 };                        
00692 __CTASSERT(sizeof(NBFPointLight)%8==0);
00693 
00694 // The NBFSpotLight structure represents a spot light.
00696 struct NBFSpotLight : public NBFLightSource
00697 {
00698   float3_t    attenuation;        
00699 
00700 
00701 
00702   float       cutoffAngle;        
00703 
00704   float       falloffExponent;    
00705   PADDING(4);                     
00706 };
00707 __CTASSERT(sizeof(NBFSpotLight)%8==0);
00708 
00710 
00711 struct NBFStateSet : public NBFObject
00712 {
00713   uint_t      numStateAttribs;    
00714   uint_t      stateAttribs;       
00715 };
00716 __CTASSERT(sizeof(NBFStateSet)%8==0);
00717 
00719 
00721 struct NBFStateAttribute : public NBFObject
00722 {
00723 };
00724 __CTASSERT(sizeof(NBFStateAttribute)%8==0);
00725 
00727 
00728 struct NBFCgFx : public NBFStateAttribute
00729 {
00730   str_t       file;               
00731   uint_t      numTweaks;          
00732   uint_t      tweaks;             
00733 
00734   uint_t      currTech;           
00735   PADDING(4);                     
00736 };
00737 __CTASSERT(sizeof(NBFCgFx)%8==0);
00738 
00740 
00741 struct NBFFaceAttribute : public NBFStateAttribute
00742 {
00743   float3_t    ambientColor;         
00744   ubyte_t     backFaceCulling;      
00745   ubyte_t     polygonOffsetEnabled; 
00746   PADDING(2);                       
00747   float       polygonOffsetFactor;  
00748 
00749   float       polygonOffsetUnits;   
00750 
00751   ubyte_t     twoSidedLighting;     
00752   PADDING(7);                       
00753 };
00754 __CTASSERT(sizeof(NBFFaceAttribute)%8==0);
00755 
00757 
00758 struct NBFMaterial : public NBFStateAttribute
00759 {
00760   float3_t    ambientColor;       
00761   float3_t    diffuseColor;       
00762   float3_t    emissiveColor;      
00763   float       opacity;            
00764   float3_t    specularColor;      
00765   float       specularExponent;   
00766 };
00767 __CTASSERT(sizeof(NBFMaterial)%8==0);
00768 
00770 
00771 struct NBFTextureAttribute : public NBFStateAttribute
00772 {
00773   uint_t      numBindings;        
00774   uint_t      bindings;           
00775 
00776 };
00777 __CTASSERT(sizeof(NBFTextureAttribute)%8==0);
00778 
00780 
00783 struct NBFTextureAttributeItem : public NBFObject
00784 {
00785   str_t         file;               
00786   uint_t        texType;            
00787 
00788 
00789   uint_t        texEnvMode;         
00790 
00791   uint_t        texWrapS;           
00792 
00793   uint_t        texWrapT;           
00794 
00795   uint_t        texWrapR;           
00796 
00797   uint_t        minFilter;          
00798 
00799   uint_t        magFilter;          
00800 
00801   float4_t      texBorderColor;     
00802   trafo_t       trafo;              
00803   uint_t        texGenMode[4];      
00804   float4_t      texGenPlane[4];     
00805 };
00806 __CTASSERT(sizeof(NBFTextureAttributeItem)%8==0);
00807 
00808 #pragma pack(pop)

Generated on Tue Mar 1 13:19:20 2005 for NVSGSDK by NVIDIA