=================== R_ParseImageProgram_r If pic is NULL, the timestamps will be filled in, but no image will be generated If both pic and timestamps are NULL, it will just advance past it, which can be used to parse an image program from a text stream. =================== */
| 369 | =================== |
| 370 | */ |
| 371 | static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *height, |
| 372 | ID_TIME_T *timestamps, textureDepth_t *depth ) { |
| 373 | idToken token; |
| 374 | float scale; |
| 375 | ID_TIME_T timestamp; |
| 376 | |
| 377 | src.ReadToken( &token ); |
| 378 | AppendToken( token ); |
| 379 | |
| 380 | if ( !token.Icmp( "heightmap" ) ) { |
| 381 | MatchAndAppendToken( src, "(" ); |
| 382 | |
| 383 | if ( !R_ParseImageProgram_r( src, pic, width, height, timestamps, depth ) ) { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | MatchAndAppendToken( src, "," ); |
| 388 | |
| 389 | src.ReadToken( &token ); |
| 390 | AppendToken( token ); |
| 391 | scale = token.GetFloatValue(); |
| 392 | |
| 393 | // process it |
| 394 | if ( pic ) { |
| 395 | R_HeightmapToNormalMap( *pic, *width, *height, scale ); |
| 396 | if ( depth ) { |
| 397 | *depth = TD_BUMP; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | MatchAndAppendToken( src, ")" ); |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | if ( !token.Icmp( "addnormals" ) ) { |
| 406 | byte *pic2 = NULL; |
| 407 | int width2, height2; |
| 408 | |
| 409 | MatchAndAppendToken( src, "(" ); |
| 410 | |
| 411 | if ( !R_ParseImageProgram_r( src, pic, width, height, timestamps, depth ) ) { |
| 412 | return false; |
| 413 | } |
| 414 | |
| 415 | MatchAndAppendToken( src, "," ); |
| 416 | |
| 417 | if ( !R_ParseImageProgram_r( src, pic ? &pic2 : NULL, &width2, &height2, timestamps, depth ) ) { |
| 418 | if ( pic ) { |
| 419 | R_StaticFree( *pic ); |
| 420 | *pic = NULL; |
| 421 | } |
| 422 | return false; |
| 423 | } |
| 424 | |
| 425 | // process it |
| 426 | if ( pic ) { |
| 427 | R_AddNormalMaps( *pic, *width, *height, pic2, width2, height2 ); |
| 428 | R_StaticFree( pic2 ); |
no test coverage detected