00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLGLTexture.h"
00028
00029 #include "OSDLOpenGL.h"
00030 #include "OSDLBasic.h"
00031 #include "OSDLVideo.h"
00032 #include "OSDLSurface.h"
00033
00034
00035 #ifdef OSDL_USES_CONFIG_H
00036 #include <OSDLConfig.h>
00037 #endif // OSDL_USES_CONFIG_H
00038
00039 #if OSDL_ARCH_NINTENDO_DS
00040 #include "OSDLConfigForNintendoDS.h"
00041 #endif // OSDL_ARCH_NINTENDO_DS
00042
00043
00044 #if OSDL_USES_SDL
00045 #include "SDL.h"
00046 #endif // OSDL_USES_SDL
00047
00048
00049 #ifdef OSDL_HAVE_OPENGL
00050 #include "SDL_opengl.h"
00051 #endif // OSDL_HAVE_OPENGL
00052
00053
00054
00055
00056
00057 #include "OSDLIncludeCorrecter.h"
00058
00059
00060 using std::string ;
00061
00062 using namespace Ceylan ;
00063 using namespace Ceylan::Log ;
00064 using namespace Ceylan::Maths ;
00065
00066 using namespace OSDL::Video ;
00067 using namespace OSDL::Video::Pixels ;
00068 using namespace OSDL::Video::OpenGL ;
00069
00070
00071
00072 GLTexture::TextureDimensionality GLTexture::CurrentTextureDimensionality =
00073 TwoDim ;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 #if OSDL_VERBOSE_VIDEO_MODULE
00088
00089 #define LOG_DEBUG_TEXTURE(message) LogPlug::debug(message)
00090 #define LOG_TRACE_TEXTURE(message) LogPlug::trace(message)
00091 #define LOG_WARNING_TEXTURE(message) LogPlug::warning(message)
00092
00093 #else // OSDL_VERBOSE_VIDEO_MODULE
00094
00095 #define LOG_DEBUG_TEXTURE(message)
00096 #define LOG_TRACE_TEXTURE(message)
00097 #define LOG_WARNING_TEXTURE(message)
00098
00099 #endif // OSDL_VERBOSE_VIDEO_MODULE
00100
00101
00102
00103 GLTextureException::GLTextureException( const std::string & reason ) :
00104 OpenGLException( reason )
00105 {
00106
00107 }
00108
00109
00110
00111 GLTextureException::~GLTextureException() throw()
00112 {
00113
00114 }
00115
00116
00117
00118
00119
00120 GLTexture::GLTexture( const std::string textureFilename,
00121 TextureFlavour flavour, bool preload ):
00122 Ceylan::LoadableWithContent<Surface>( textureFilename ),
00123 _id( 0 ),
00124 _flavour( flavour ),
00125 _unloadable( false )
00126 {
00127
00128 #if OSDL_USES_OPENGL
00129
00130 LOG_DEBUG_TEXTURE( "Constructing a GLTexture from a file" ) ;
00131
00132 if ( preload )
00133 {
00134
00135 try
00136 {
00137
00138 load() ;
00139
00140 }
00141 catch( const Ceylan::LoadableException & e )
00142 {
00143
00144 throw GLTextureException(
00145 "GLTexture constructor failed while preloading: "
00146 + e.toString() ) ;
00147
00148 }
00149
00150 }
00151
00152 #else // OSDL_USES_OPENGL
00153
00154
00155
00156
00157
00158
00159 throw GLTextureException( "GLTexture constructor failed: "
00160 "no OpenGL support available." ) ;
00161
00162 #endif // OSDL_USES_OPENGL
00163
00164 }
00165
00166
00167
00168 GLTexture::GLTexture( Surface & sourceSurface, TextureFlavour flavour ) :
00169 Ceylan::LoadableWithContent<Surface>( "(non applicable)" ),
00170 _id( 0 ),
00171 _flavour( flavour ),
00172 _unloadable( true )
00173 {
00174
00175 LOG_DEBUG_TEXTURE( "Constructing a GLTexture from a surface" ) ;
00176
00177 setUpInternalSurfaceFrom( sourceSurface ) ;
00178
00179 }
00180
00181
00182
00183
00184 GLTexture::~GLTexture() throw()
00185 {
00186
00187 LOG_DEBUG_TEXTURE( "Deleting a GLTexture" ) ;
00188
00189 try
00190 {
00191
00192
00193
00194
00195
00196
00197
00198
00199 remove() ;
00200
00201 }
00202 catch( const GLTextureException & e )
00203 {
00204
00205 LogPlug::error( "GLTexture destructor failed "
00206 "while removing it from video card: " + e.toString() ) ;
00207
00208 }
00209
00210
00211 try
00212 {
00213
00214 if ( hasContent() )
00215 {
00216
00217 if ( _unloadable )
00218 {
00219
00220 delete _content ;
00221 _content = 0 ;
00222
00223 }
00224 else
00225 {
00226
00227 unload() ;
00228
00229 }
00230
00231 }
00232
00233 }
00234 catch( const Ceylan::LoadableException & e )
00235 {
00236
00237 LogPlug::error( "GLTexture destructor failed while unloading texture: "
00238 + e.toString() ) ;
00239
00240 }
00241
00242
00243
00244
00245 }
00246
00247
00248
00249 Length GLTexture::getWidth() const
00250 {
00251
00252 if ( _content != 0 )
00253 return _content->getWidth() ;
00254 else
00255 throw GLTextureException( "GLTexture::getWidth called "
00256 "whereas texture not loaded." ) ;
00257
00258 }
00259
00260
00261
00262 Length GLTexture::getHeight() const
00263 {
00264
00265 if ( _content != 0 )
00266 return _content->getHeight() ;
00267 else
00268 throw GLTextureException( "GLTexture::getHeight called "
00269 "whereas texture not loaded." ) ;
00270
00271 }
00272
00273
00274
00275
00276
00277 bool GLTexture::wasUploaded() const
00278 {
00279
00280 return ( _id != 0 ) ;
00281
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 void GLTexture::upload()
00295 {
00296
00297 #if OSDL_USES_OPENGL
00298
00299
00300
00301
00302
00303
00304
00305
00306 #if OSDL_DEBUG
00307
00308
00309
00310 if ( ! OSDL::getExistingCommonModule().getVideoModule().hasOpenGLContext() )
00311 throw GLTextureException( "GLTexture::upload called "
00312 "whereas OpenGL has not been initialized (no OpenGL context)." ) ;
00313
00314 #endif // OSDL_DEBUG
00315
00316
00317 if ( wasUploaded() )
00318 throw GLTextureException( "GLTexture::upload called "
00319 "whereas a texture identifier is already available." ) ;
00320
00321 if ( ! hasContent() )
00322 load() ;
00323
00324
00325
00326 glGenTextures( 1, & _id ) ;
00327
00328
00329 #if OSDL_CHECK_OPENGL_CALLS
00330
00331 switch ( ::glGetError() )
00332 {
00333
00334 case GL_NO_ERROR:
00335 break ;
00336
00337 case GL_INVALID_VALUE:
00338 throw GLTextureException(
00339 "GLTexture::upload failed (glGenTextures): "
00340 "invalid number of requested names." ) ;
00341 break ;
00342
00343 case GL_INVALID_OPERATION:
00344 throw GLTextureException(
00345 "GLTexture::upload failed (glGenTextures): "
00346 "incorrectly executed between the execution of glBegin and "
00347 "the corresponding execution of glEnd." ) ;
00348 break ;
00349
00350 default:
00351 LogPlug::warning( "GLTexture::upload failed (glGenTextures): "
00352 "unexpected error reported." ) ;
00353 break ;
00354
00355 }
00356
00357 #endif // OSDL_CHECK_OPENGL_CALLS
00358
00359 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ) ;
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 glBindTexture( GL_TEXTURE_2D,
00374 _id ) ;
00375
00376
00377 #if OSDL_CHECK_OPENGL_CALLS
00378
00379 switch ( ::glGetError() )
00380 {
00381
00382 case GL_NO_ERROR:
00383 break ;
00384
00385 case GL_INVALID_ENUM:
00386 throw GLTextureException(
00387 "GLTexture::upload failed (glBindTexture): "
00388 "target is not an allowed value." ) ;
00389 break ;
00390
00391 case GL_INVALID_OPERATION:
00392 throw GLTextureException(
00393 "GLTexture::upload failed (glBindTexture): "
00394 "wrong dimensionality or incorrectly executed between "
00395 "the execution of glBegin and the corresponding execution "
00396 "of glEnd." ) ;
00397 break ;
00398
00399 default:
00400 LogPlug::warning( "GLTexture::upload failed (glBindTexture): "
00401 "unexpected error reported." ) ;
00402 break ;
00403
00404 }
00405
00406 #endif // OSDL_CHECK_OPENGL_CALLS
00407
00408
00409
00410
00411
00412
00413 SetTextureFlavour( _flavour ) ;
00414
00415
00416 Length width = getWidth() ;
00417 Length height = getHeight() ;
00418
00419
00420 if ( IsAPowerOfTwo( width ) && IsAPowerOfTwo( height ) )
00421 {
00422
00423 LogPlug::trace( "GLTexture::upload: glTexImage2D with "
00424 + Ceylan::toString( width ) + "x"
00425 + Ceylan::toString( height ) + ", for: " + _content->toString() ) ;
00426
00427
00428 glTexImage2D(
00429 GL_TEXTURE_2D,
00430 0,
00431 GL_RGBA,
00432 width,
00433 height,
00434 0,
00435 GL_RGBA,
00436 GL_UNSIGNED_BYTE,
00437 _content->getPixels() ) ;
00438
00439 #if OSDL_CHECK_OPENGL_CALLS
00440
00441 switch ( ::glGetError() )
00442 {
00443
00444 case GL_NO_ERROR:
00445 break ;
00446
00447 case GL_INVALID_ENUM:
00448 throw GLTextureException(
00449 "GLTexture::upload failed (glTexImage2D): "
00450 "invalid enum." ) ;
00451 break ;
00452
00453 case GL_INVALID_VALUE:
00454 throw GLTextureException(
00455 "GLTexture::upload failed (glTexImage2D): "
00456 "invalid value." ) ;
00457 break ;
00458
00459 case GL_INVALID_OPERATION:
00460 throw GLTextureException(
00461 "GLTexture::upload failed (glTexImage2D): "
00462 "incorrectly executed between the execution of "
00463 "glBegin and the corresponding execution of glEnd." ) ;
00464 break ;
00465
00466 default:
00467 throw GLTextureException(
00468 "GLTexture::upload failed (glTexImage2D): "
00469 "unexpected error reported." ) ;
00470 break ;
00471
00472 }
00473
00474 #endif // OSDL_CHECK_OPENGL_CALLS
00475
00476 }
00477 else
00478 {
00479
00480 LogPlug::trace( "GLTexture::upload: gluBuild2DMipmaps with "
00481 + Ceylan::toString( width ) + "x"
00482 + Ceylan::toString( height ) + ", for: " + _content->toString() ) ;
00483
00484
00485
00486 GLU::Int res = gluBuild2DMipmaps(
00487 GL_TEXTURE_2D,
00488 GL_RGBA,
00489 width,
00490 height,
00491 GL_RGBA,
00492 GL_UNSIGNED_BYTE,
00493 _content->getPixels() ) ;
00494
00495 #if OSDL_CHECK_OPENGL_CALLS
00496
00497 switch ( res )
00498 {
00499
00500 case 0:
00501
00502 break ;
00503
00504 case GLU_INVALID_ENUM:
00505 throw GLTextureException(
00506 "GLTexture::upload failed (gluBuild2DMipmaps): "
00507 "invalid enum." ) ;
00508 break ;
00509
00510 case GLU_INVALID_VALUE:
00511 throw GLTextureException(
00512 "GLTexture::upload failed (gluBuild2DMipmaps): "
00513 "invalid value." ) ;
00514 break ;
00515
00516 default:
00517 throw GLTextureException(
00518 "GLTexture::upload failed (gluBuild2DMipmaps): "
00519 "unexpected error reported." ) ;
00520 break ;
00521
00522 }
00523
00524 #endif // OSDL_CHECK_OPENGL_CALLS
00525
00526 }
00527
00528
00529
00530
00531 #else // OSDL_USES_OPENGL
00532
00533 throw GLTextureException( "GLTexture::upload failed: "
00534 "OpenGL support not available." ) ;
00535
00536 #endif // OSDL_USES_OPENGL
00537
00538 }
00539
00540
00541
00542
00543 void GLTexture::remove()
00544 {
00545
00546 #if OSDL_USES_OPENGL
00547
00548 if ( _id != 0 )
00549 {
00550
00551 ::glDeleteTextures( 1, & _id ) ;
00552
00553 _id = 0 ;
00554
00555 #if OSDL_CHECK_OPENGL_CALLS
00556
00557 switch ( ::glGetError() )
00558 {
00559
00560 case GL_NO_ERROR:
00561 break ;
00562
00563 case GL_INVALID_VALUE:
00564 throw GLTextureException( "GLTexture::remove failed: "
00565 "incorrect negative ID specified." ) ;
00566 break ;
00567
00568 case GL_INVALID_OPERATION:
00569 throw GLTextureException( "GLTexture::remove failed: "
00570 "incorrectly executed between the execution of glBegin "
00571 "and the corresponding execution of glEnd." ) ;
00572 break ;
00573
00574 default:
00575 LogPlug::warning( "GLTexture::remove failed: "
00576 "unexpected error reported." ) ;
00577 break ;
00578
00579 }
00580
00581 #endif // OSDL_CHECK_OPENGL_CALLS
00582
00583 }
00584
00585
00586 #endif // OSDL_USES_OPENGL
00587
00588 }
00589
00590
00591
00592
00593 void GLTexture::setAsCurrent() const
00594 {
00595
00596 #if OSDL_USES_OPENGL
00597
00598
00599
00600 if ( _id == 0 )
00601 throw GLTextureException( "GLTexture::setAsCurrent: texture not loaded "
00602 "(no available texture identifier)" ) ;
00603
00604
00605 ::glBindTexture( GL_TEXTURE_2D, _id ) ;
00606
00607
00608 #if OSDL_CHECK_OPENGL_CALLS
00609
00610 switch ( ::glGetError() )
00611 {
00612
00613 case GL_NO_ERROR:
00614 break ;
00615
00616 case GL_INVALID_VALUE:
00617 throw GLTextureException( "GLTexture::setAsCurrent failed: "
00618 "incorrect target specified." ) ;
00619 break ;
00620
00621 case GL_INVALID_OPERATION:
00622 throw GLTextureException( "GLTexture::setAsCurrent failed: "
00623 "invalid operation, texture has a dimensionality that "
00624 "does not match that of target, "
00625 "or incorrectly executed between the execution of glBegin "
00626 "and the corresponding execution of glEnd." ) ;
00627 break ;
00628
00629 default:
00630 LogPlug::warning( "GLTexture::setAsCurrent failed: "
00631 "unexpected error reported." ) ;
00632 break ;
00633 }
00634
00635 #endif // OSDL_CHECK_OPENGL_CALLS
00636
00637 #else // OSDL_USES_OPENGL
00638
00639 throw GLTextureException( "GLTexture::setAsCurrent failed: "
00640 "OpenGL support not available." ) ;
00641
00642 #endif // OSDL_USES_OPENGL
00643
00644 }
00645
00646
00647
00648 bool GLTexture::isResident()
00649 {
00650
00651 #if OSDL_USES_OPENGL
00652
00653 LOG_DEBUG_TEXTURE( "GLTexture::isResident" ) ;
00654
00655 if ( _id == 0 )
00656 return false ;
00657
00658
00659
00660 GLboolean residences ;
00661
00662
00663
00664
00665
00666
00667
00668 bool res = ( ::glAreTexturesResident(
00669 1,
00670 & _id,
00671 &residences ) == GL_TRUE ) ;
00672
00673 #if OSDL_CHECK_OPENGL_CALLS
00674
00675 switch ( ::glGetError() )
00676 {
00677
00678 case GL_NO_ERROR:
00679 break ;
00680
00681 case GL_INVALID_VALUE:
00682 throw GLTextureException( "GLTexture::isResident failed: "
00683 "invalid (negative?) texture number." ) ;
00684 break ;
00685
00686 case GL_INVALID_OPERATION:
00687 throw GLTextureException( "GLTexture::isResident failed: "
00688 "invalid operation, incorrectly executed between "
00689 "the execution of glBegin and the corresponding execution "
00690 "of glEnd." ) ;
00691 break ;
00692
00693 default:
00694 LogPlug::warning( "GLTexture::isResident failed: "
00695 "unexpected error reported." ) ;
00696 break ;
00697
00698 }
00699
00700 #endif // OSDL_CHECK_OPENGL_CALLS
00701
00702 return res ;
00703
00704 #else // OSDL_USES_OPENGL
00705
00706 throw GLTextureException( "GLTexture::isResident failed: "
00707 "OpenGL support not available." ) ;
00708
00709 #endif // OSDL_USES_OPENGL
00710
00711 }
00712
00713
00714
00715
00716
00717
00718
00719
00720 bool GLTexture::load()
00721 {
00722
00723 if ( hasContent() )
00724 return false ;
00725
00726 LOG_DEBUG_TEXTURE( "Constructing a GLTexture from file " + _contentPath ) ;
00727
00728 try
00729 {
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 Surface * originalSurface = & Surface::LoadImage( _contentPath,
00743 false, false ) ;
00744
00745 setUpInternalSurfaceFrom( * originalSurface ) ;
00746
00747 }
00748 catch( const Ceylan::Exception & e )
00749 {
00750
00751 throw Ceylan::LoadableException( "GLTexture::load failed: "
00752 "unable to load from '" + _contentPath + "': " + e.toString() ) ;
00753
00754 }
00755
00756 return true ;
00757
00758
00759
00760 }
00761
00762
00763
00764 bool GLTexture::unload()
00765 {
00766
00767 if ( ! hasContent() )
00768 return false ;
00769
00770
00771
00772 if ( _unloadable )
00773 return false ;
00774
00775 delete _content ;
00776 _content = 0 ;
00777
00778
00779 return true ;
00780
00781 }
00782
00783
00784
00785 const string GLTexture::toString( Ceylan::VerbosityLevels level ) const
00786 {
00787
00788 string res = "OpenGL texture, " ;
00789
00790 if ( _id == 0 )
00791 res += "which has no OpenGL identifier" ;
00792 else
00793 res += "whose OpenGL identifier is " + Ceylan::toString( _id ) ;
00794
00795 res += ", whose content path is '" + _contentPath ;
00796
00797 if ( _content == 0 )
00798 res += "', and which content is not loaded" ;
00799 else
00800 res += "', which content is loaded. "
00801 "Its current size (width x height) is "
00802 + Ceylan::toString( getWidth() ) + "x"
00803 + Ceylan::toString( getHeight() ) + " pixels" ;
00804
00805 return res ;
00806
00807 }
00808
00809
00810
00811
00812
00813
00814
00815
00816 GLTexture::TextureDimensionality GLTexture::GetTextureDimensionality()
00817 {
00818
00819 return CurrentTextureDimensionality ;
00820
00821 }
00822
00823
00824
00825 void GLTexture::SetTextureDimensionality(
00826 TextureDimensionality newDimensionality )
00827 {
00828
00829 CurrentTextureDimensionality = newDimensionality ;
00830
00831 }
00832
00833
00834
00835 void GLTexture::SetTextureFlavour( TextureFlavour textureFlavour )
00836 {
00837
00838 #if OSDL_USES_OPENGL
00839
00840 LogPlug::trace( "GLTexture::SetTextureFlavour" ) ;
00841
00842 switch( textureFlavour )
00843 {
00844
00845
00846 case None:
00847 return ;
00848 break ;
00849
00850
00851 case Basic:
00852
00853 LogPlug::trace( "GLTexture::SetTextureFlavour: Basic" ) ;
00854
00855
00856
00857
00858
00859
00860 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) ;
00861
00862
00863
00864
00865
00866
00867 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ;
00868
00869
00870
00871
00872
00873
00874 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) ;
00875
00876
00877
00878
00879
00880
00881 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ) ;
00882
00883 break ;
00884
00885
00886 case For2D:
00887
00888 LogPlug::trace( "GLTexture::SetTextureFlavour: For2D" ) ;
00889
00890
00891 OpenGLContext::EnableFeature( OpenGL::TwoDimensionalTexturing ) ;
00892
00893 GLTexture::SetTextureDimensionality( GLTexture::TwoDim ) ;
00894
00895
00896
00897
00898
00899 SetTextureEnvironmentParameter( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
00900 GL_MODULATE ) ;
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
00917 GL_LINEAR ) ;
00918
00919
00920
00921
00922
00923
00924 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
00925 GL_LINEAR ) ;
00926
00927
00928
00929
00930
00931
00932 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) ;
00933
00934
00935
00936
00937
00938
00939 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ) ;
00940
00941 break ;
00942
00943
00944 case For3D:
00945
00946 LogPlug::trace( "GLTexture::SetTextureFlavour: For3D" ) ;
00947
00948
00949 OpenGLContext::EnableFeature( OpenGL::TwoDimensionalTexturing ) ;
00950
00951 GLTexture::SetTextureDimensionality( GLTexture::TwoDim ) ;
00952
00953
00954
00955
00956
00957 SetTextureEnvironmentParameter( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
00958 GL_MODULATE ) ;
00959
00960
00961
00962
00963
00964 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
00965 GL_LINEAR ) ;
00966
00967
00968
00969
00970
00971
00972 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
00973 GL_LINEAR ) ;
00974
00975
00976
00977
00978
00979
00980 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) ;
00981
00982
00983
00984
00985
00986
00987 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ) ;
00988
00989 break ;
00990
00991
00992 default:
00993 throw GLTextureException(
00994 "GLTexture::SetTextureFlavour: unknown texture flavour: "
00995 + Ceylan::toString( textureFlavour ) + "." ) ;
00996 break ;
00997
00998 }
00999
01000 #else // OSDL_USES_OPENGL
01001
01002 throw GLTextureException( "GLTexture::SetTextureFlavour failed: "
01003 "OpenGL support not available." ) ;
01004
01005 #endif // OSDL_USES_OPENGL
01006
01007 }
01008
01009
01010
01011 void GLTexture::SetTextureEnvironmentParameter(
01012 GLEnumeration targetEnvironment,
01013 GLEnumeration environmentParameter,
01014 GLfloat parameterValue )
01015 {
01016
01017 #if OSDL_USES_OPENGL
01018
01019 glTexEnvf( targetEnvironment, environmentParameter, parameterValue ) ;
01020
01021
01022 #if OSDL_CHECK_OPENGL_CALLS
01023
01024 switch ( ::glGetError() )
01025 {
01026
01027 case GL_NO_ERROR:
01028 break ;
01029
01030 case GL_INVALID_ENUM:
01031 throw GLTextureException(
01032 "GLTexture::SetTextureEnvironmentParameter: "
01033 "invalid enumeration." ) ;
01034 break ;
01035
01036 case GL_INVALID_VALUE:
01037 throw GLTextureException(
01038 "GLTexture::SetTextureEnvironmentParameter: "
01039 "invalid enumeration." ) ;
01040 break ;
01041
01042 case GL_INVALID_OPERATION:
01043 throw GLTextureException(
01044 "GLTexture::SetTextureEnvironmentParameter: "
01045 "incorrectly executed between the execution of glBegin and "
01046 "the corresponding execution of glEnd." ) ;
01047 break ;
01048
01049 default:
01050 throw GLTextureException(
01051 "GLTexture::SetTextureEnvironmentParameter: "
01052 "unexpected error reported." ) ;
01053 break ;
01054
01055 }
01056
01057 #endif // OSDL_CHECK_OPENGL_CALLS
01058
01059
01060 #else // OSDL_USES_OPENGL
01061
01062 throw GLTextureException(
01063 "GLTexture::SetTextureEnvironmentParameter failed: "
01064 "no OpenGL support available" ) ;
01065
01066 #endif // OSDL_USES_OPENGL
01067
01068 }
01069
01070
01071
01072 void GLTexture::UnbindCurrentTexture()
01073 {
01074
01075 #if OSDL_USES_OPENGL
01076
01077 glBindTexture( GL_TEXTURE_2D,
01078 0 ) ;
01079
01080
01081 #if OSDL_CHECK_OPENGL_CALLS
01082
01083 switch ( ::glGetError() )
01084 {
01085
01086 case GL_NO_ERROR:
01087 break ;
01088
01089 case GL_INVALID_ENUM:
01090 throw GLTextureException(
01091 "GLTexture::UnbindCurrentTexture failed: "
01092 "target is not an allowed value." ) ;
01093 break ;
01094
01095 case GL_INVALID_OPERATION:
01096 throw GLTextureException(
01097 "GLTexture::UnbindCurrentTexture failed: "
01098 "wrong dimensionality or incorrectly executed between "
01099 "the execution of glBegin and the corresponding execution "
01100 "of glEnd." ) ;
01101 break ;
01102
01103 default:
01104 LogPlug::warning( "GLTexture::UnbindCurrentTexture failed: "
01105 "unexpected error reported." ) ;
01106 break ;
01107
01108 }
01109
01110 #endif // OSDL_CHECK_OPENGL_CALLS
01111
01112 #else // OSDL_USES_OPENGL
01113
01114 throw GLTextureException(
01115 "GLTexture::UnbindCurrentTexture failed: "
01116 "no OpenGL support available" ) ;
01117
01118 #endif // OSDL_USES_OPENGL
01119
01120 }
01121
01122
01123
01124 std::string GLTexture::GetExtensionForFlavour( TextureFlavour flavour )
01125 {
01126
01127 switch( flavour )
01128 {
01129
01130 case None:
01131 return ".tex" ;
01132
01133 case Basic:
01134 return ".tex" ;
01135
01136 case For2D:
01137 return ".tex2D" ;
01138
01139 case For3D:
01140 return ".tex3D" ;
01141
01142 default:
01143 throw GLTextureException( "GLTexture::GetExtensionForFlavour: "
01144 "unknown flavour (" + Ceylan::toString(flavour) + ")" ) ;
01145
01146 }
01147
01148 }
01149
01150
01151
01152 void GLTexture::SetTextureEnvironmentParameter(
01153 GLEnumeration targetEnvironment,
01154 GLEnumeration environmentParameter,
01155 const GLfloat * parameterValues )
01156 {
01157
01158 #if OSDL_USES_OPENGL
01159
01160 glTexEnvfv( targetEnvironment, environmentParameter, parameterValues ) ;
01161
01162
01163 #if OSDL_CHECK_OPENGL_CALLS
01164
01165 switch ( ::glGetError() )
01166 {
01167
01168 case GL_NO_ERROR:
01169 break ;
01170
01171 case GL_INVALID_ENUM:
01172 throw GLTextureException(
01173 "GLTexture::SetTextureEnvironmentParameter: "
01174 "invalid enumeration." ) ;
01175 break ;
01176
01177 case GL_INVALID_VALUE:
01178 throw GLTextureException(
01179 "GLTexture::SetTextureEnvironmentParameter: "
01180 "invalid enumeration." ) ;
01181 break ;
01182
01183 case GL_INVALID_OPERATION:
01184 throw GLTextureException(
01185 "GLTexture::SetTextureEnvironmentParameter: "
01186 "incorrectly executed between the execution of glBegin and "
01187 "the corresponding execution of glEnd." ) ;
01188 break ;
01189
01190 default:
01191 throw GLTextureException(
01192 "GLTexture::SetTextureEnvironmentParameter: "
01193 "unexpected error reported." ) ;
01194 break ;
01195
01196 }
01197
01198 #endif // OSDL_CHECK_OPENGL_CALLS
01199
01200
01201 #else // OSDL_USES_OPENGL
01202
01203 throw GLTextureException(
01204 "GLTexture::SetTextureEnvironmentParameter failed: "
01205 "no OpenGL support available" ) ;
01206
01207 #endif // OSDL_USES_OPENGL
01208
01209 }
01210
01211
01212
01213
01214
01215
01216
01217
01218 void GLTexture::setUpInternalSurfaceFrom( Surface & sourceSurface )
01219 {
01220
01221 if ( ( sourceSurface.getFlags() & Surface::AlphaBlendingBlit ) != 0 )
01222 sourceSurface.setAlpha( 0,
01223 AlphaTransparent ) ;
01224
01225
01226
01227 _content = new Surface( VideoModule::SoftwareSurface,
01228 sourceSurface.getWidth(), sourceSurface.getHeight(),
01229 32, RedMask, GreenMask, BlueMask, AlphaMask ) ;
01230
01231 sourceSurface.blitTo( *_content ) ;
01232
01233 delete & sourceSurface ;
01234
01235 }
01236