| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | #include <stdio.h> |
|---|
| 31 | #include <string.h> |
|---|
| 32 | |
|---|
| 33 | #include <osg/Notify> |
|---|
| 34 | #include <osg/TexEnv> |
|---|
| 35 | #include <osg/Texture2D> |
|---|
| 36 | #include <osg/StateSet> |
|---|
| 37 | #include <osg/GL> |
|---|
| 38 | |
|---|
| 39 | #include <osgDB/FileNameUtils> |
|---|
| 40 | #include <osgDB/FileUtils> |
|---|
| 41 | #include <osgDB/Registry> |
|---|
| 42 | |
|---|
| 43 | #include <iostream> |
|---|
| 44 | #include <fstream> |
|---|
| 45 | |
|---|
| 46 | #include "AttrData.h" |
|---|
| 47 | |
|---|
| 48 | typedef signed char int8; |
|---|
| 49 | typedef unsigned char uint8; |
|---|
| 50 | typedef signed short int16; |
|---|
| 51 | typedef unsigned short uint16; |
|---|
| 52 | typedef signed int int32; |
|---|
| 53 | typedef unsigned int uint32; |
|---|
| 54 | typedef float float32; |
|---|
| 55 | typedef double float64; |
|---|
| 56 | |
|---|
| 57 | #define READ(DST) readField(file, (void*)&(DST), sizeof(DST)) |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | static int isLittleEndianMachine() |
|---|
| 61 | { |
|---|
| 62 | int a = 1; |
|---|
| 63 | return (int)(*(char*)&a); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | static void endian2(void* pSrc, int nSrc, void* pDst) |
|---|
| 68 | { |
|---|
| 69 | if (nSrc == 2) |
|---|
| 70 | { |
|---|
| 71 | short tmp1; |
|---|
| 72 | tmp1 = *(short *)pSrc; |
|---|
| 73 | tmp1 = (tmp1 << 8) | ((tmp1 >> 8) & 0xff); |
|---|
| 74 | *(short *)pDst = tmp1; |
|---|
| 75 | } |
|---|
| 76 | else if (nSrc == 4) |
|---|
| 77 | { |
|---|
| 78 | uint32 tmp1; |
|---|
| 79 | tmp1 = *(uint32 *)pSrc; |
|---|
| 80 | tmp1 = (tmp1 << 24) | ((tmp1 << 8) & 0xff0000) | ((tmp1 >> 8) & 0xff00) | ((tmp1 >> 24) & 0xff); |
|---|
| 81 | *(uint32 *)pDst = tmp1; |
|---|
| 82 | } |
|---|
| 83 | else if (nSrc == 8) |
|---|
| 84 | { |
|---|
| 85 | uint32 tmp1, tmp2; |
|---|
| 86 | tmp1 = *(uint32 *)pSrc; |
|---|
| 87 | tmp2 = *(1 + (uint32 *)pSrc); |
|---|
| 88 | tmp1 = (tmp1 << 24) | ((tmp1 << 8) & 0xff0000) | ((tmp1 >> 8) & 0xff00) | ((tmp1 >> 24) & 0xff); |
|---|
| 89 | tmp2 = (tmp2 << 24) | ((tmp2 << 8) & 0xff0000) | ((tmp2 >> 8) & 0xff00) | ((tmp2 >> 24) & 0xff); |
|---|
| 90 | *(uint32 *)pDst = tmp2; |
|---|
| 91 | *(1 + (uint32 *)pDst) = tmp1; |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | using namespace osg; |
|---|
| 97 | |
|---|
| 98 | class Attr |
|---|
| 99 | { |
|---|
| 100 | public : |
|---|
| 101 | |
|---|
| 102 | enum MinFilterMode { |
|---|
| 103 | MIN_FILTER_POINT = 0, |
|---|
| 104 | MIN_FILTER_BILINEAR = 1, |
|---|
| 105 | MIN_FILTER_MIPMAP = 2, |
|---|
| 106 | MIN_FILTER_MIPMAP_POINT = 3, |
|---|
| 107 | MIN_FILTER_MIPMAP_LINEAR = 4, |
|---|
| 108 | MIN_FILTER_MIPMAP_BILINEAR = 5, |
|---|
| 109 | MIN_FILTER_MIPMAP_TRILINEAR = 6, |
|---|
| 110 | MIN_FILTER_NONE = 7, |
|---|
| 111 | MIN_FILTER_BICUBIC = 8, |
|---|
| 112 | MIN_FILTER_BILINEAR_GEQUAL = 9, |
|---|
| 113 | MIN_FILTER_BILINEAR_LEQUAL = 10, |
|---|
| 114 | MIN_FILTER_BICUBIC_GEQUAL = 11, |
|---|
| 115 | MIN_FILTER_BICUBIC_LEQUAL = 12 |
|---|
| 116 | }; |
|---|
| 117 | |
|---|
| 118 | enum MagFilterMode { |
|---|
| 119 | MAG_FILTER_POINT = 0, |
|---|
| 120 | MAG_FILTER_BILINEAR = 1, |
|---|
| 121 | MAG_FILTER_NONE = 2, |
|---|
| 122 | MAG_FILTER_BICUBIC = 3, |
|---|
| 123 | MAG_FILTER_SHARPEN = 4, |
|---|
| 124 | MAG_FILTER_ADD_DETAIL = 5, |
|---|
| 125 | MAG_FILTER_MODULATE_DETAIL = 6, |
|---|
| 126 | MAG_FILTER_BILINEAR_GEQUAL = 7, |
|---|
| 127 | MAG_FILTER_BILINEAR_LEQUAL = 8, |
|---|
| 128 | MAG_FILTER_BICUBIC_GEQUAL = 9, |
|---|
| 129 | MAG_FILTER_BICUBIC_LEQUAL = 10 |
|---|
| 130 | }; |
|---|
| 131 | |
|---|
| 132 | enum WrapMode { |
|---|
| 133 | WRAP_REPEAT = 0, |
|---|
| 134 | WRAP_CLAMP = 1 |
|---|
| 135 | }; |
|---|
| 136 | |
|---|
| 137 | enum TexEnvMode { |
|---|
| 138 | TEXENV_MODULATE = 0, |
|---|
| 139 | TEXENV_BLEND = 1, |
|---|
| 140 | TEXENV_DECAL = 2, |
|---|
| 141 | TEXENV_COLOR = 3 |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | enum Projection { |
|---|
| 145 | PROJECTION_FLAT = 0, |
|---|
| 146 | PROJECTION_LAMBERT_CONIC = 3, |
|---|
| 147 | PROJECTION_UTM = 4, |
|---|
| 148 | PROJECTION_UNDEFINED = 7 |
|---|
| 149 | }; |
|---|
| 150 | |
|---|
| 151 | enum Datum { |
|---|
| 152 | DATUM_WGS84 = 0, |
|---|
| 153 | DATUM_WGS72 = 1, |
|---|
| 154 | DATUM_BESSEL = 2, |
|---|
| 155 | DATUM_CLARK_1866 = 3, |
|---|
| 156 | DATUM_NAD27 = 4 |
|---|
| 157 | }; |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | Attr(int version) : _flt_version(version) { init(); } |
|---|
| 161 | void init(); |
|---|
| 162 | void readField(std::ifstream& file, void* buf, size_t size); |
|---|
| 163 | bool readAttrFile(const char* szName); |
|---|
| 164 | flt::AttrData* createOsgStateSet(); |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | int32 texels_u; |
|---|
| 169 | int32 textel_v; |
|---|
| 170 | int32 direction_u; |
|---|
| 171 | int32 direction_v; |
|---|
| 172 | int32 x_up; |
|---|
| 173 | int32 y_up; |
|---|
| 174 | int32 fileFormat; |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | int32 minFilterMode; |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | int32 magFilterMode; |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | int32 wrapMode; |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | int32 wrapMode_u; |
|---|
| 213 | int32 wrapMode_v; |
|---|
| 214 | int32 modifyFlag; |
|---|
| 215 | int32 pivot_x; |
|---|
| 216 | int32 pivot_y; |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | int32 texEnvMode; |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | int32 intensityAsAlpha; |
|---|
| 228 | int32 spare1[8]; |
|---|
| 229 | float64 size_u; |
|---|
| 230 | float64 size_v; |
|---|
| 231 | int32 originCode; |
|---|
| 232 | int32 kernelVersion; |
|---|
| 233 | int32 intFormat; |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | int32 extFormat; |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | int32 useMips; |
|---|
| 249 | float32 _mipMapKernel[8]; |
|---|
| 250 | int32 useLodScale; |
|---|
| 251 | float32 lod0; |
|---|
| 252 | float32 scale0; |
|---|
| 253 | float32 lod1; |
|---|
| 254 | float32 scale1; |
|---|
| 255 | float32 lod2; |
|---|
| 256 | float32 scale2; |
|---|
| 257 | float32 lod3; |
|---|
| 258 | float32 scale3; |
|---|
| 259 | float32 lod4; |
|---|
| 260 | float32 scale4; |
|---|
| 261 | float32 lod5; |
|---|
| 262 | float32 scale5; |
|---|
| 263 | float32 lod6; |
|---|
| 264 | float32 scale6; |
|---|
| 265 | float32 lod7; |
|---|
| 266 | float32 scale7; |
|---|
| 267 | |
|---|
| 268 | float32 clamp; |
|---|
| 269 | int32 magFilterAlpha; |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | int32 magFilterColor; |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | float32 reserved1; |
|---|
| 294 | float32 reserved2[8]; |
|---|
| 295 | float64 lambertMeridian; |
|---|
| 296 | float64 lambertUpperLat; |
|---|
| 297 | float64 lambertlowerLat; |
|---|
| 298 | float64 reserved3; |
|---|
| 299 | float32 spare2[5]; |
|---|
| 300 | int32 useDetail; |
|---|
| 301 | int32 txDetail_j; |
|---|
| 302 | int32 txDetail_k; |
|---|
| 303 | int32 txDetail_m; |
|---|
| 304 | int32 txDetail_n; |
|---|
| 305 | int32 txDetail_s; |
|---|
| 306 | int32 useTile; |
|---|
| 307 | float32 txTile_ll_u; |
|---|
| 308 | float32 txTile_ll_v; |
|---|
| 309 | float32 txTile_ur_u; |
|---|
| 310 | float32 txTile_ur_v; |
|---|
| 311 | int32 projection; |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | int32 earthModel; |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | int32 reserved4; |
|---|
| 323 | int32 utmZone; |
|---|
| 324 | int32 imageOrigin; |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | int32 geoUnits; |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | int32 reserved5; |
|---|
| 332 | int32 reserved6; |
|---|
| 333 | int32 hemisphere; |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | int32 reserved7; |
|---|
| 337 | int32 reserved8; |
|---|
| 338 | int32 spare3[149]; |
|---|
| 339 | char comments[512]; |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | int32 reserved9[13]; |
|---|
| 346 | int32 attrVersion; |
|---|
| 347 | |
|---|
| 348 | int32 controlPoints; |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | int32 reserved10; |
|---|
| 352 | #if 0 |
|---|
| 353 | |
|---|
| 354 | { |
|---|
| 355 | float64 texel_u; |
|---|
| 356 | float64 texel_v; |
|---|
| 357 | float64 geoPoint[2]; |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | int32 subtextures; |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | { |
|---|
| 373 | char name[32]; |
|---|
| 374 | int32 left; |
|---|
| 375 | |
|---|
| 376 | int32 bottom; |
|---|
| 377 | |
|---|
| 378 | int32 right; |
|---|
| 379 | |
|---|
| 380 | int32 top; |
|---|
| 381 | |
|---|
| 382 | } |
|---|
| 383 | #endif |
|---|
| 384 | |
|---|
| 385 | void read(); |
|---|
| 386 | |
|---|
| 387 | private : |
|---|
| 388 | |
|---|
| 389 | int _flt_version; |
|---|
| 390 | }; |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | void Attr::init() |
|---|
| 395 | { |
|---|
| 396 | texels_u = 0; |
|---|
| 397 | textel_v = 0; |
|---|
| 398 | direction_u = 0; |
|---|
| 399 | direction_v = 0; |
|---|
| 400 | x_up = 0; |
|---|
| 401 | y_up = 0; |
|---|
| 402 | fileFormat = -1; |
|---|
| 403 | minFilterMode = MIN_FILTER_NONE; |
|---|
| 404 | magFilterMode = MAG_FILTER_POINT; |
|---|
| 405 | wrapMode = WRAP_REPEAT; |
|---|
| 406 | wrapMode_u = WRAP_REPEAT; |
|---|
| 407 | wrapMode_v = WRAP_REPEAT; |
|---|
| 408 | modifyFlag = 0; |
|---|
| 409 | pivot_x = 0; |
|---|
| 410 | pivot_y = 0; |
|---|
| 411 | texEnvMode = TEXENV_MODULATE; |
|---|
| 412 | intensityAsAlpha = 0; |
|---|
| 413 | size_u = 0; |
|---|
| 414 | size_v = 0; |
|---|
| 415 | originCode = 0; |
|---|
| 416 | kernelVersion = 0; |
|---|
| 417 | intFormat = 0; |
|---|
| 418 | extFormat = 0; |
|---|
| 419 | useMips = 0; |
|---|
| 420 | |
|---|
| 421 | useLodScale = 0; |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | clamp = 0; |
|---|
| 428 | magFilterAlpha = 2; |
|---|
| 429 | magFilterColor = 2; |
|---|
| 430 | lambertMeridian = 0; |
|---|
| 431 | lambertUpperLat = 0; |
|---|
| 432 | lambertlowerLat = 0; |
|---|
| 433 | useDetail = 0; |
|---|
| 434 | txDetail_j = 0; |
|---|
| 435 | txDetail_k = 0; |
|---|
| 436 | txDetail_m = 0; |
|---|
| 437 | txDetail_n = 0; |
|---|
| 438 | txDetail_s = 0; |
|---|
| 439 | useTile = 0; |
|---|
| 440 | txTile_ll_u = 0; |
|---|
| 441 | txTile_ll_v = 0; |
|---|
| 442 | txTile_ur_u = 0; |
|---|
| 443 | txTile_ur_v = 0; |
|---|
| 444 | projection = PROJECTION_UNDEFINED; |
|---|
| 445 | earthModel = DATUM_WGS84; |
|---|
| 446 | utmZone = 0; |
|---|
| 447 | imageOrigin = 0; |
|---|
| 448 | geoUnits = 0; |
|---|
| 449 | hemisphere = 1; |
|---|
| 450 | comments[0] = '\0'; |
|---|
| 451 | attrVersion = 0; |
|---|
| 452 | controlPoints = 0; |
|---|
| 453 | |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | void Attr::readField(std::ifstream& file, void* buf, size_t size) |
|---|
| 458 | { |
|---|
| 459 | if (file.eof()) return; |
|---|
| 460 | file.read((char*)buf, size); |
|---|
| 461 | if(::isLittleEndianMachine()) |
|---|
| 462 | ::endian2(buf, size, buf); |
|---|
| 463 | } |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | bool Attr::readAttrFile(const char* szName) |
|---|
| 467 | { |
|---|
| 468 | int n; |
|---|
| 469 | std::ifstream file; |
|---|
| 470 | |
|---|
| 471 | file.open (szName, std::ios::in | std::ios::binary); |
|---|
| 472 | |
|---|
| 473 | READ( texels_u ); |
|---|
| 474 | READ( textel_v ); |
|---|
| 475 | READ( direction_u ); |
|---|
| 476 | READ( direction_v ); |
|---|
| 477 | READ( x_up ); |
|---|
| 478 | READ( y_up ); |
|---|
| 479 | READ( fileFormat ); |
|---|
| 480 | READ( minFilterMode ); |
|---|
| 481 | READ( magFilterMode ); |
|---|
| 482 | READ( wrapMode ); |
|---|
| 483 | READ( wrapMode_u ); |
|---|
| 484 | READ( wrapMode_v ); |
|---|
| 485 | READ( modifyFlag ); |
|---|
| 486 | READ( pivot_x ); |
|---|
| 487 | READ( pivot_y ); |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | if (_flt_version <= 11) return true; |
|---|
| 491 | |
|---|
| 492 | READ( texEnvMode ); |
|---|
| 493 | READ( intensityAsAlpha ); |
|---|
| 494 | for (n=0; n<8; n++) { |
|---|
| 495 | READ(spare1[n]); } |
|---|
| 496 | READ( size_u ); |
|---|
| 497 | READ( size_v ); |
|---|
| 498 | READ( originCode ); |
|---|
| 499 | READ( kernelVersion ); |
|---|
| 500 | READ( intFormat ); |
|---|
| 501 | READ( extFormat ); |
|---|
| 502 | READ( useMips ); |
|---|
| 503 | for (n=0; n<8; n++) { |
|---|
| 504 | READ(_mipMapKernel[n]); } |
|---|
| 505 | READ( useLodScale ); |
|---|
| 506 | READ( lod0 ); |
|---|
| 507 | READ( scale0 ); |
|---|
| 508 | READ( lod1 ); |
|---|
| 509 | READ( scale1 ); |
|---|
| 510 | READ( lod2 ); |
|---|
| 511 | READ( scale2 ); |
|---|
| 512 | READ( lod3 ); |
|---|
| 513 | READ( scale3 ); |
|---|
| 514 | READ( lod4 ); |
|---|
| 515 | READ( scale4 ); |
|---|
| 516 | READ( lod5 ); |
|---|
| 517 | READ( scale5 ); |
|---|
| 518 | READ( lod6 ); |
|---|
| 519 | READ( scale6 ); |
|---|
| 520 | READ( lod7 ); |
|---|
| 521 | READ( scale7 ); |
|---|
| 522 | READ( clamp ); |
|---|
| 523 | READ( magFilterAlpha ); |
|---|
| 524 | READ( magFilterColor ); |
|---|
| 525 | READ( reserved1 ); |
|---|
| 526 | for (n=0; n<8; n++) { |
|---|
| 527 | READ(reserved2[n]); } |
|---|
| 528 | READ( lambertMeridian ); |
|---|
| 529 | READ( lambertUpperLat ); |
|---|
| 530 | READ( lambertlowerLat ); |
|---|
| 531 | READ( reserved3 ); |
|---|
| 532 | |
|---|
| 533 | for (n=0; n<5; n++) { |
|---|
| 534 | READ(spare2[n]); } |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | int32 dummyAjust; |
|---|
| 540 | READ( dummyAjust); |
|---|
| 541 | |
|---|
| 542 | READ( useDetail ); |
|---|
| 543 | READ( txDetail_j ); |
|---|
| 544 | READ( txDetail_k ); |
|---|
| 545 | READ( txDetail_m ); |
|---|
| 546 | READ( txDetail_n ); |
|---|
| 547 | READ( txDetail_s ); |
|---|
| 548 | READ( useTile ); |
|---|
| 549 | READ( txTile_ll_u ); |
|---|
| 550 | READ( txTile_ll_v ); |
|---|
| 551 | READ( txTile_ur_u ); |
|---|
| 552 | READ( txTile_ur_v ); |
|---|
| 553 | READ( projection ); |
|---|
| 554 | READ( earthModel ); |
|---|
| 555 | READ( reserved4 ); |
|---|
| 556 | READ( utmZone ); |
|---|
| 557 | READ( imageOrigin); |
|---|
| 558 | READ( geoUnits ); |
|---|
| 559 | READ( reserved5 ); |
|---|
| 560 | READ( reserved6 ); |
|---|
| 561 | READ( hemisphere ); |
|---|
| 562 | READ( reserved7 ); |
|---|
| 563 | READ( reserved8 ); |
|---|
| 564 | for (n=0; n<149; n++) { |
|---|
| 565 | READ(spare3[n]); } |
|---|
| 566 | file.read(comments, sizeof(comments)); |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | if (_flt_version <= 12) return true; |
|---|
| 570 | |
|---|
| 571 | for (n=0; n<13; n++) { |
|---|
| 572 | READ(reserved9[n]); } |
|---|
| 573 | READ( attrVersion ); |
|---|
| 574 | READ( controlPoints); |
|---|
| 575 | READ( reserved10 ); |
|---|
| 576 | |
|---|
| 577 | file.close(); |
|---|
| 578 | return true; |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | flt::AttrData* Attr::createOsgStateSet() |
|---|
| 583 | { |
|---|
| 584 | TexEnv* osgTexEnv = new TexEnv; |
|---|
| 585 | Texture2D* osgTexture = new Texture2D; |
|---|
| 586 | flt::AttrData* attrdata = new flt::AttrData; |
|---|
| 587 | |
|---|
| 588 | if ((wrapMode_u != WRAP_CLAMP) && ((wrapMode_u != WRAP_REPEAT))) |
|---|
| 589 | wrapMode_u = wrapMode; |
|---|
| 590 | if ((wrapMode_v != WRAP_CLAMP) && ((wrapMode_v != WRAP_REPEAT))) |
|---|
| 591 | wrapMode_v = wrapMode; |
|---|
| 592 | |
|---|
| 593 | if (wrapMode_u == WRAP_CLAMP) osgTexture->setWrap(Texture2D::WRAP_S,Texture2D::CLAMP); |
|---|
| 594 | else osgTexture->setWrap(Texture2D::WRAP_S,Texture2D::REPEAT); |
|---|
| 595 | |
|---|
| 596 | if (wrapMode_v == WRAP_CLAMP) osgTexture->setWrap(Texture2D::WRAP_T,Texture2D::CLAMP); |
|---|
| 597 | else osgTexture->setWrap(Texture2D::WRAP_T,Texture2D::REPEAT); |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | switch (texEnvMode) |
|---|
| 601 | { |
|---|
| 602 | case TEXENV_MODULATE: |
|---|
| 603 | osgTexEnv->setMode(TexEnv::MODULATE); |
|---|
| 604 | break; |
|---|
| 605 | case TEXENV_BLEND: |
|---|
| 606 | osgTexEnv->setMode(TexEnv::BLEND); |
|---|
| 607 | break; |
|---|
| 608 | case TEXENV_DECAL: |
|---|
| 609 | osgTexEnv->setMode(TexEnv::DECAL); |
|---|
| 610 | break; |
|---|
| 611 | case TEXENV_COLOR: |
|---|
| 612 | osgTexEnv->setMode(TexEnv::REPLACE); |
|---|
| 613 | break; |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | switch (minFilterMode) |
|---|
| 657 | { |
|---|
| 658 | case MIN_FILTER_POINT: |
|---|
| 659 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::NEAREST); |
|---|
| 660 | break; |
|---|
| 661 | case MIN_FILTER_BILINEAR: |
|---|
| 662 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::LINEAR); |
|---|
| 663 | break; |
|---|
| 664 | case MIN_FILTER_MIPMAP_POINT: |
|---|
| 665 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::NEAREST_MIPMAP_NEAREST); |
|---|
| 666 | break; |
|---|
| 667 | case MIN_FILTER_MIPMAP_LINEAR: |
|---|
| 668 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::NEAREST_MIPMAP_LINEAR); |
|---|
| 669 | break; |
|---|
| 670 | case MIN_FILTER_MIPMAP_BILINEAR: |
|---|
| 671 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::LINEAR_MIPMAP_NEAREST); |
|---|
| 672 | break; |
|---|
| 673 | case MIN_FILTER_MIPMAP_TRILINEAR: |
|---|
| 674 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::LINEAR_MIPMAP_LINEAR); |
|---|
| 675 | break; |
|---|
| 676 | case MIN_FILTER_BICUBIC: |
|---|
| 677 | case MIN_FILTER_BILINEAR_GEQUAL: |
|---|
| 678 | case MIN_FILTER_BILINEAR_LEQUAL: |
|---|
| 679 | case MIN_FILTER_BICUBIC_GEQUAL: |
|---|
| 680 | case MIN_FILTER_BICUBIC_LEQUAL: |
|---|
| 681 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::LINEAR_MIPMAP_NEAREST); |
|---|
| 682 | break; |
|---|
| 683 | default: |
|---|
| 684 | osgTexture->setFilter(osg::Texture2D::MIN_FILTER, Texture2D::LINEAR_MIPMAP_LINEAR); |
|---|
| 685 | break; |
|---|
| 686 | break; |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | switch (magFilterMode) |
|---|
| 695 | { |
|---|
| 696 | case MAG_FILTER_POINT: |
|---|
| 697 | osgTexture->setFilter(osg::Texture2D::MAG_FILTER, Texture2D::NEAREST); |
|---|
| 698 | break; |
|---|
| 699 | case MAG_FILTER_BILINEAR: |
|---|
| 700 | case MAG_FILTER_BILINEAR_GEQUAL: |
|---|
| 701 | case MAG_FILTER_BILINEAR_LEQUAL: |
|---|
| 702 | case MAG_FILTER_SHARPEN: |
|---|
| 703 | case MAG_FILTER_BICUBIC: |
|---|
| 704 | case MAG_FILTER_BICUBIC_GEQUAL: |
|---|
| 705 | case MAG_FILTER_BICUBIC_LEQUAL: |
|---|
| 706 | case MAG_FILTER_ADD_DETAIL: |
|---|
| 707 | case MAG_FILTER_MODULATE_DETAIL: |
|---|
| 708 | osgTexture->setFilter(osg::Texture2D::MAG_FILTER, Texture2D::LINEAR); |
|---|
| 709 | break; |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | attrdata->stateset = new StateSet; |
|---|
| 725 | attrdata->stateset->setTextureAttribute( 0, osgTexEnv ); |
|---|
| 726 | attrdata->stateset->setTextureAttributeAndModes( 0, osgTexture, StateAttribute::ON ); |
|---|
| 727 | attrdata->useDetail = useDetail; |
|---|
| 728 | attrdata->txDetail_j = txDetail_j; |
|---|
| 729 | attrdata->txDetail_k = txDetail_k; |
|---|
| 730 | attrdata->txDetail_m = txDetail_m; |
|---|
| 731 | attrdata->txDetail_n = txDetail_n; |
|---|
| 732 | attrdata->txDetail_s = txDetail_s; |
|---|
| 733 | if (magFilterMode == MAG_FILTER_MODULATE_DETAIL) |
|---|
| 734 | attrdata->modulateDetail = true; |
|---|
| 735 | else |
|---|
| 736 | attrdata->modulateDetail = false; |
|---|
| 737 | |
|---|
| 738 | return attrdata; |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | class ReaderWriterATTR : public osgDB::ReaderWriter |
|---|
| 743 | { |
|---|
| 744 | public: |
|---|
| 745 | virtual const char* className() { return "ATTR Image Attribute Reader/Writer"; } |
|---|
| 746 | |
|---|
| 747 | virtual bool acceptsExtension(const std::string& extension) |
|---|
| 748 | { |
|---|
| 749 | return osgDB::equalCaseInsensitive(extension,"attr"); |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options*) |
|---|
| 753 | { |
|---|
| 754 | std::string ext = osgDB::getLowerCaseFileExtension(file); |
|---|
| 755 | if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; |
|---|
| 756 | |
|---|
| 757 | std::string fileName = osgDB::findDataFile( file ); |
|---|
| 758 | if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | char buf[256]; |
|---|
| 762 | int version=0; |
|---|
| 763 | |
|---|
| 764 | const osgDB::ReaderWriter::Options* rwOptions= |
|---|
| 765 | osgDB::Registry::instance()->getOptions(); |
|---|
| 766 | |
|---|
| 767 | if (rwOptions) |
|---|
| 768 | { |
|---|
| 769 | sscanf(rwOptions->getOptionString().c_str(),"%s %d", buf, &version); |
|---|
| 770 | if (strcmp(buf, "FLT_VER")) version=0; |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | Attr attr(version); |
|---|
| 774 | |
|---|
| 775 | if (!attr.readAttrFile(fileName.c_str())) |
|---|
| 776 | { |
|---|
| 777 | return "Unable to open \""+fileName+"\""; |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | flt::AttrData* attrdata = attr.createOsgStateSet(); |
|---|
| 783 | |
|---|
| 784 | notify(INFO) << "texture attribute read ok" << std::endl; |
|---|
| 785 | return attrdata; |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | }; |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | osgDB::RegisterReaderWriterProxy<ReaderWriterATTR> g_readerWriter_ATTR_Proxy; |
|---|