Changeset 438 for branches/thune/thread_safe/gl/gx_dt.c
- Timestamp:
- 07/25/07 22:34:48 (16 months ago)
- Files:
-
- 1 modified
-
branches/thune/thread_safe/gl/gx_dt.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/gl/gx_dt.c
r403 r438 1 1 /*============================================================================ 2 2 Thune OpenGL Module 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 305 305 static void _texCoord( TextureDef* tex, const UCell* cell ) 306 306 { 307 tex->width = cell->coord.elem[0]; 308 tex->height = cell->coord.elem[1]; 307 if( ur_is(cell, UT_COORD) ) 308 { 309 tex->width = cell->coord.elem[0]; 310 tex->height = cell->coord.elem[1]; 311 } 312 else 313 { 314 tex->width = ur_int(cell); 315 tex->height = 1; 316 } 317 309 318 tex->pixels = 0; 310 319 tex->comp = 4; … … 327 336 328 337 329 // (texture! raster -- tex) 330 // (texture! coord -- tex) 331 // (texture! [raster!/coord! 'mipmap 'nearest 'linear 'repeat 'clamp] -- tex) 338 /* 339 (texture! raster -- tex) 340 (texture! coord -- tex) ; 2D Texture 341 (texture! int -- tex) ; 1D Texture 342 (texture! [raster!/coord!/int! 343 binary! 344 'mipmap 'nearest 'linear 'repeat 'clamp 345 'gray 'rgb' 'rgba ] -- tex) 346 */ 332 347 UR_CALL( make_texture ) 333 348 { … … 337 352 int mipmap = 0; 338 353 UIndex rastN = 0; 354 GLenum target = GL_TEXTURE_2D; 339 355 UCell* res = ur_s_prev(tos); 340 356 … … 353 369 else if( ur_is(tos, UT_COORD) ) 354 370 { 371 _texCoord( &def, tos ); 372 goto build; 373 } 374 else if( ur_is(tos, UT_INT) ) 375 { 376 target = GL_TEXTURE_1D; 355 377 _texCoord( &def, tos ); 356 378 goto build; … … 380 402 _texRast( &def, ur_rastHead(val) ); 381 403 } 404 else if( ur_is(val, UT_BINARY) ) 405 { 406 def.pixels = ur_bin(val)->ptr.b; 407 } 382 408 else if( ur_is(val, UT_COORD) ) 383 409 { 410 _texCoord( &def, val ); 411 } 412 else if( ur_is(val, UT_INT) ) 413 { 414 target = GL_TEXTURE_1D; 384 415 _texCoord( &def, val ); 385 416 } … … 410 441 mipmap = 1; 411 442 break; 443 444 case UR_ATOM_GRAY: 445 def.comp = 1; 446 def.format = GL_LUMINANCE; 447 break; 448 449 case UR_ATOM_RGB: 450 def.comp = 3; 451 def.format = GL_RGB; 452 break; 453 454 case UR_ATOM_RGBA: 455 def.comp = 4; 456 def.format = GL_RGBA; 457 break; 412 458 } 459 break; 460 461 case UT_INT: 462 target = GL_TEXTURE_1D; 463 _texCoord( &def, it ); 413 464 break; 414 465 … … 416 467 _texCoord( &def, it ); 417 468 break; 469 470 case UT_BINARY: 471 def.pixels = ur_bin(it)->ptr.b; 418 472 } 419 473 ++it; … … 431 485 432 486 name = gltex_alloc( &pool ); 433 glBindTexture( GL_TEXTURE_2D, name );487 glBindTexture( target, name ); 434 488 435 489 // TODO: Support texture type of GL_FLOAT. 436 if( mipmap ) 437 { 438 gluBuild2DMipmaps( GL_TEXTURE_2D, def.comp, def.width, def.height, 439 def.format, GL_UNSIGNED_BYTE, def.pixels ); 490 491 if( target == GL_TEXTURE_2D ) 492 { 493 if( mipmap ) 494 { 495 gluBuild2DMipmaps( GL_TEXTURE_2D, def.comp, def.width, def.height, 496 def.format, GL_UNSIGNED_BYTE, def.pixels ); 497 } 498 else 499 { 500 // Ensure that a non-mipmap minifying filter is used. 501 // Using a mipmap filter can cause FBO format errors and textures 502 // to not appear. 503 if( def.min_filter != GL_NEAREST ) 504 def.min_filter = GL_LINEAR; 505 506 glTexImage2D( GL_TEXTURE_2D, 0, def.comp, def.width, def.height, 507 0, def.format, GL_UNSIGNED_BYTE, def.pixels ); 508 } 440 509 } 441 510 else 442 511 { 443 // Ensure that a non-mipmap minifying filter is used. 444 // Using a mipmap filter can cause FBO format errors and textures to 445 // not appear. 446 if( def.min_filter != GL_NEAREST ) 447 def.min_filter = GL_LINEAR; 448 449 glTexImage2D( GL_TEXTURE_2D, 0, def.comp, def.width, def.height, 0, 450 def.format, GL_UNSIGNED_BYTE, def.pixels ); 512 if( mipmap ) 513 { 514 gluBuild1DMipmaps( GL_TEXTURE_1D, def.comp, def.width, 515 def.format, GL_UNSIGNED_BYTE, def.pixels ); 516 } 517 else 518 { 519 if( def.min_filter != GL_NEAREST ) 520 def.min_filter = GL_LINEAR; 521 522 glTexImage1D( GL_TEXTURE_1D, 0, def.comp, def.width, 523 0, def.format, GL_UNSIGNED_BYTE, def.pixels ); 524 } 451 525 } 452 526 … … 464 538 465 539 // GL_CLAMP, GL_CLAMP_TO_EDGE, GL_REPEAT. 466 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, def.wrap );467 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, def.wrap );540 glTexParameteri( target, GL_TEXTURE_WRAP_S, def.wrap ); 541 glTexParameteri( target, GL_TEXTURE_WRAP_T, def.wrap ); 468 542 469 543 // TODO: Support all GL_TEXTURE_MIN_FILTER types. 470 544 // GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, etc. 471 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, def.min_filter );545 glTexParameteri( target, GL_TEXTURE_MIN_FILTER, def.min_filter ); 472 546 473 547 // GL_NEAREST, GL_LINEAR 474 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, def.mag_filter );548 glTexParameteri( target, GL_TEXTURE_MAG_FILTER, def.mag_filter ); 475 549 476 550 ur_initType( res, UT_TEXTURE ); … … 522 596 if( phase == UR_GC_PHASE_MARK ) 523 597 { 598 // Clear any unchecked GL error. 599 #ifdef DEBUG 600 GLenum err = glGetError(); 601 if( err ) 602 printf( "recycle_texture - glGetError() returned %d\n", err ); 603 #else 604 glGetError(); 605 #endif 606 524 607 gllist_gcBegin(); 525 608 gltex_gcBegin(); … … 941 1024 static int cmp_nop( UThread* ut, const UCell* a, const UCell* b, int mode ) 942 1025 { 1026 (void) ut; 1027 (void) a; 1028 (void) b; 1029 (void) mode; 943 1030 return 0; 944 1031 }
