1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2011 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGOFANCILLARYRECORDS_H_
40 #define _OSGOFANCILLARYRECORDS_H_
42 #include "OSGFileIODef.h"
43 #include "OSGOFRecords.h"
45 #include "OSGTextureEnvChunk.h"
46 #include "OSGTextureObjChunk.h"
50 //---------------------------------------------------------------------------
52 //---------------------------------------------------------------------------
54 /*! \ingroup GrpFileIOOpenFlight
58 class OSG_FILEIO_DLLMAPPING OFColorPaletteRecord
: public OFAncillaryRecord
62 typedef OFAncillaryRecord Inherited
;
64 typedef std::vector
<Color4f
> ColorStore
;
65 typedef std::vector
<std::string
> ColorNameStore
;
67 /*---------------------------------------------------------------------*/
69 static OFRecordFactoryBase::RegisterRecord _regHelper
;
71 /*---------------------------------------------------------------------*/
74 ColorNameStore colorNames
;
76 /*---------------------------------------------------------------------*/
78 OFColorPaletteRecord(const OFRecordHeader
&oHeader
,
80 virtual ~OFColorPaletteRecord(void );
84 static const UInt16 OpCode
= 32;
86 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
89 /*---------------------------------------------------------------------*/
91 virtual bool read(std::istream
&is
);
93 /*---------------------------------------------------------------------*/
95 virtual UInt16
getOpCode(void) const;
97 /*---------------------------------------------------------------------*/
99 virtual void dump(UInt32 uiIndent
) const;
101 /*---------------------------------------------------------------------*/
103 Color4f
getColor(UInt32 uiIdx
) const;
105 bool hasNames(void ) const;
106 std::string
const &getName (UInt32 uiIdx
) const;
109 /*! \ingroup GrpFileIOOpenFlight
111 typedef RefCountPtr
<OFColorPaletteRecord
,
112 MemObjRefCountPolicy
> OFColorPaletteRecordRCPtr
;
114 //---------------------------------------------------------------------------
116 //---------------------------------------------------------------------------
118 /*! \ingroup GrpFileIOOpenFlight
122 class OSG_FILEIO_DLLMAPPING OFTexturePaletteRecord
: public OFAncillaryRecord
126 typedef OFAncillaryRecord Inherited
;
130 Int32 numTexelU
; // 0 4 number of texels in u direction
131 Int32 numTexelV
; // 4 8 number of texels in v direction
132 Int32 realSizeU
; // 8 4 obsolete
133 Int32 realSizeV
; // 12 4 obsolete
134 Int32 upX
; // 16 4 x component of up vector
135 Int32 upY
; // 20 4 y component of up vector
136 Int32 fileFormat
; // 24 4 file format type
137 // 0 AT&T image 8 pattern
138 // 1 AT&T image 8 template
139 // 2 SGI itensity modulation
140 // 3 SGI inensity w/alpha
143 Int32 minFilter
; // 28 4 minifiaction filter
146 // 2 mipmap (obsolete)
150 // 7 mipmap trilinear
157 Int32 magFilter
; // 32 4 magnification filter
169 Int32 wrapUV
; // 36 4 wrap u,v
173 Int32 wrapU
; // 40 4 wrap u
176 // 3 none - use wrapUV
178 Int32 wrapV
; // 44 4 wrap v
181 // 3 none - use wrapUV
183 Int32 modified
; // 48 4 modified flag (internal use only)
184 Int32 pivotX
; // 52 4 x pivot for rotating textures
185 Int32 pivotY
; // 56 4 y pivot for rotating textures
186 Int32 envMode
; // 60 4 environment mode
193 // many more that are not read at this point.
195 GLenum
getMinFilter(void);
196 GLenum
getMagFilter(void);
198 GLenum
getWrapU (void);
199 GLenum
getWrapV (void);
201 GLenum
getEnvMode (void);
204 GLenum
getWrap(Int32 wrap
);
207 bool readTexAttr(TexAttr
&attr
);
209 /*---------------------------------------------------------------------*/
211 static OFRecordFactoryBase::RegisterRecord _regHelper
;
213 /*---------------------------------------------------------------------*/
215 Char8 szFilename
[200]; // 4 200 File name of texture pattern
216 Int32 iPatternIdx
; // 204 4 Texture pattern index
217 Int32 iPatternX
; // 208 4*2 Location in the texture palette (x, y)
220 /*---------------------------------------------------------------------*/
222 TextureObjChunkUnrecPtr pTexObj
;
223 TextureEnvChunkUnrecPtr pTexEnv
;
225 /*---------------------------------------------------------------------*/
227 OFTexturePaletteRecord(const OFRecordHeader
&oHeader
,
229 virtual ~OFTexturePaletteRecord(void );
233 static const UInt16 OpCode
= 64;
235 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
238 /*---------------------------------------------------------------------*/
240 virtual bool read(std::istream
&is
);
242 /*---------------------------------------------------------------------*/
244 virtual UInt16
getOpCode(void) const;
246 /*---------------------------------------------------------------------*/
248 virtual void dump(UInt32 uiIndent
) const;
250 /*---------------------------------------------------------------------*/
252 Int32
getPatternIdx(void);
253 TextureObjChunk
*getTexObj (void) const;
254 TextureEnvChunk
*getTexEnv (void) const;
257 /*! \ingroup GrpFileIOOpenFlight
259 typedef RefCountPtr
<OFTexturePaletteRecord
,
260 MemObjRefCountPolicy
> OFTexturePaletteRecordRCPtr
;
262 //---------------------------------------------------------------------------
264 //---------------------------------------------------------------------------
266 /*! \ingroup GrpFileIOOpenFlight
270 class OSG_FILEIO_DLLMAPPING OFVertexPaletteRecord
: public OFAncillaryRecord
274 /*---------------------------------------------------------------------*/
280 UInt16 uiColNameIdx
; // 4 2 Color name index
281 Int16 iFlags
; // 6 2 Flags (bits, from left to right)
282 // 0 = Start hard edge
288 Int32 iPackedCol
; // 32 4 Packed color (a, b, g, r) - always
289 // specified when the vertex has color
290 UInt32 iColIdx
; // 36 4 Vertex color index - valid only if vertex
291 // has color and Packed color flag is not set
292 Int32 iPad1
; // 52 4 Reserved
298 bool operator <(const UInt32 uiOff
) const;
299 bool operator <(const VertexInfo
&vInfo
) const;
302 /*---------------------------------------------------------------------*/
304 static const UInt8 PosIdx
= 0;
305 static const UInt8 ColIdx
= 1;
306 static const UInt8 NormIdx
= 2;
307 static const UInt8 TexCoordIdx
= 3;
309 static const UInt8 HasPos
= 0x01;
310 static const UInt8 HasCol
= 0x02;
311 static const UInt8 HasNorm
= 0x04;
312 static const UInt8 HasTexCoord
= 0x08;
316 typedef OFAncillaryRecord Inherited
;
318 /*---------------------------------------------------------------------*/
320 static OFRecordFactoryBase::RegisterRecord _regHelper
;
322 /*---------------------------------------------------------------------*/
324 std::vector
<Pnt3f
> vPositions
;
325 std::vector
<Vec3f
> vNormals
;
326 std::vector
<Vec2f
> vTexCoords
;
327 std::vector
<VertexInfo
> vVertexInfo
;
329 /*---------------------------------------------------------------------*/
331 OFVertexPaletteRecord(const OFRecordHeader
&oHeader
,
334 virtual ~OFVertexPaletteRecord(void);
338 static const UInt16 OpCode
= 67;
340 /*---------------------------------------------------------------------*/
342 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
345 virtual bool read(std::istream
&is
);
347 /*---------------------------------------------------------------------*/
349 virtual UInt16
getOpCode(void) const;
351 /*---------------------------------------------------------------------*/
353 const VertexInfo
*getVertexInfo(UInt32 uiOffset
) const;
355 const Pnt3f
&getPos (UInt32 uiIdx
) const;
356 const Vec3f
&getNormal (UInt32 uiIdx
) const;
357 const Vec2f
&getTexCoord (UInt32 uiIdx
) const;
360 bool operator <(const UInt32 uiOff
,
361 const OFVertexPaletteRecord::VertexInfo
&vInfo
);
363 /*! \ingroup GrpFileIOOpenFlight
365 typedef RefCountPtr
<OFVertexPaletteRecord
,
366 MemObjRefCountPolicy
> OFVertexPaletteRecordRCPtr
;
368 //---------------------------------------------------------------------------
370 //---------------------------------------------------------------------------
372 /*! \ingroup GrpFileIOOpenFlight
376 class OSG_FILEIO_DLLMAPPING OFMaterialPaletteRecord
: public OFAncillaryRecord
380 typedef OFAncillaryRecord Inherited
;
382 /*---------------------------------------------------------------------*/
384 static OFRecordFactoryBase::RegisterRecord _regHelper
;
386 /*---------------------------------------------------------------------*/
388 Int32 iMaterialIdx
; // 4 4 Material index
389 Char8 szMaterialName
[12]; // 8 12 Material name
390 Int32 iFlags
; // 20 4 Flags
391 // 0 = Material is used
393 Color4f colAmbient
; // 24 4*3 Ambient component of material (r, g, b)
394 Color4f colDiffuse
; // 36 4*3 Diffuse component of material (r, g, b)
395 Color4f colSpecular
; // 48 4*3 Specular component of material (r, g, b)
396 Color4f colEmissive
; // 60 4*3 Emissive component of material (r, g, b)
397 Real32 fShininess
; // 72 4 Shininess - (0.0-128.0)
398 Real32 fAlpha
; // 76 4 Alpha - (0.0-1.0) where 1.0 is opaque
399 Int32 iPad
; // 80 4 Reserved
401 /*---------------------------------------------------------------------*/
403 OFMaterialPaletteRecord(const OFRecordHeader
&oHeader
,
405 virtual ~OFMaterialPaletteRecord(void );
409 static const UInt16 OpCode
= 113;
411 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
414 static const Int32 FlagMaterialUsed
= 0x80000000;
416 /*---------------------------------------------------------------------*/
418 virtual bool read(std::istream
&is
);
420 /*---------------------------------------------------------------------*/
422 virtual UInt16
getOpCode(void) const;
424 /*---------------------------------------------------------------------*/
426 virtual void dump(UInt32 uiIndent
) const;
428 /*---------------------------------------------------------------------*/
430 Int32
getMaterialIdx(void);
432 const Color4f
&getAmbient (void) const;
433 const Color4f
&getDiffuse (void) const;
434 const Color4f
&getSpecular (void) const;
435 const Color4f
&getEmissive (void) const;
436 Real32
getShininess (void) const;
437 Real32
getAlpha (void) const;
440 /*! \ingroup GrpFileIOOpenFlight
442 typedef RefCountPtr
<OFMaterialPaletteRecord
,
443 MemObjRefCountPolicy
> OFMaterialPaletteRecordRCPtr
;
445 //---------------------------------------------------------------------------
447 //---------------------------------------------------------------------------
449 /*! \ingroup GrpFileIOOpenFlight
453 class OSG_FILEIO_DLLMAPPING OFMatrixRecord
: public OFAncillaryRecord
456 /*---------------------------------------------------------------------*/
458 typedef OFAncillaryRecord Inherited
;
460 /*---------------------------------------------------------------------*/
462 static OFRecordFactoryBase::RegisterRecord _regHelper
;
464 /*---------------------------------------------------------------------*/
466 Matrix matrix
; // 4 64 4x4 matrix, row major
468 /*---------------------------------------------------------------------*/
470 OFMatrixRecord(const OFRecordHeader
&oHeader
,
472 virtual ~OFMatrixRecord(void );
476 static const UInt16 OpCode
= 49;
478 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
481 /*---------------------------------------------------------------------*/
483 virtual bool read (std::istream
&is
);
484 virtual NodeTransitPtr
convert(Node
*pNode
);
486 /*---------------------------------------------------------------------*/
488 virtual UInt16
getOpCode(void) const;
490 /*---------------------------------------------------------------------*/
492 virtual void dump(UInt32 uiIndent
) const;
494 /*---------------------------------------------------------------------*/
497 //---------------------------------------------------------------------------
499 //---------------------------------------------------------------------------
501 /*! \ingroup GrpFileIOOpenFlight
505 class OSG_FILEIO_DLLMAPPING OFIgnoredTransformRecord
: public OFAncillaryRecord
509 typedef OFAncillaryRecord Inherited
;
511 /*---------------------------------------------------------------------*/
513 static OFRecordFactoryBase::RegisterRecord _regHelperRotateAboutEdge
;
514 static OFRecordFactoryBase::RegisterRecord _regHelperTranslate
;
515 static OFRecordFactoryBase::RegisterRecord _regHelperScale
;
516 static OFRecordFactoryBase::RegisterRecord _regHelperRotateAboutPoint
;
517 static OFRecordFactoryBase::RegisterRecord _regHelperRotateScaleToPoint
;
518 static OFRecordFactoryBase::RegisterRecord _regHelperPut
;
519 static OFRecordFactoryBase::RegisterRecord _regHelperGeneralMatrix
;
521 /*---------------------------------------------------------------------*/
525 /*---------------------------------------------------------------------*/
527 OFIgnoredTransformRecord(const OFRecordHeader
&oHeader
,
529 virtual ~OFIgnoredTransformRecord(void );
533 static const UInt16 OpCodeRotateAboutEdge
= 76;
534 static const UInt16 OpCodeTranslate
= 78;
535 static const UInt16 OpCodeScale
= 79;
536 static const UInt16 OpCodeRotateAboutPoint
= 80;
537 static const UInt16 OpCodeRotateScaleToPoint
= 81;
538 static const UInt16 OpCodePut
= 82;
539 static const UInt16 OpCodeGeneralMatrix
= 94;
541 /*---------------------------------------------------------------------*/
543 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
546 /*---------------------------------------------------------------------*/
548 virtual bool read (std::istream
&is
);
549 virtual NodeTransitPtr
convert(Node
*pNode
);
551 /*---------------------------------------------------------------------*/
553 virtual UInt16
getOpCode(void) const;
555 /*---------------------------------------------------------------------*/
557 virtual void dump(UInt32 uiIndent
) const;
559 /*---------------------------------------------------------------------*/
562 //---------------------------------------------------------------------------
564 //---------------------------------------------------------------------------
566 /*! \ingroup GrpFileIOOpenFlight
570 class OSG_FILEIO_DLLMAPPING OFLongIDRecord
: public OFAncillaryRecord
573 /*---------------------------------------------------------------------*/
575 typedef OFAncillaryRecord Inherited
;
577 /*---------------------------------------------------------------------*/
579 static OFRecordFactoryBase::RegisterRecord _regHelper
;
581 /*---------------------------------------------------------------------*/
583 std::string longId
; // 4 len-4 ASCIIId of node, 0 terminates
585 /*---------------------------------------------------------------------*/
587 OFLongIDRecord(const OFRecordHeader
&oHeader
,
589 virtual ~OFLongIDRecord(void );
593 static const UInt16 OpCode
= 33;
595 static OFRecordTransitPtr
create(const OFRecordHeader
&oHeader
,
598 /*---------------------------------------------------------------------*/
600 virtual bool read (std::istream
&is
);
601 virtual NodeTransitPtr
convert(Node
*pNode
);
603 /*---------------------------------------------------------------------*/
605 virtual UInt16
getOpCode(void) const;
607 /*---------------------------------------------------------------------*/
609 virtual void dump(UInt32 uiIndent
) const;
611 /*---------------------------------------------------------------------*/
616 #endif /* _OSGOFANCILLARYRECORDS_H_ */