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 #ifndef OSDL_OPENGL_H_
00028 #define OSDL_OPENGL_H_
00029
00030
00031 #include "OSDLVideoTypes.h"
00032 #include "OSDLPixel.h"
00033 #include "OSDLPoint2D.h"
00034
00035 #include "Ceylan.h"
00036
00037
00038
00039
00040 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL
00041
00042 #include "SDL_opengl.h"
00043 #include "SDL.h"
00044
00045
00046
00047 namespace OSDL
00048 {
00049
00050
00051 namespace Video
00052 {
00053
00054
00055 namespace OpenGL
00056 {
00057
00058
00064 typedef SDL_GLattr GLAttribute ;
00065
00066 }
00067
00068 }
00069
00070
00071 }
00072
00073
00074 #else // OSDL_USES_SDL
00075
00076
00077
00078 namespace OSDL
00079 {
00080
00081
00082 namespace Video
00083 {
00084
00085
00086 namespace OpenGL
00087 {
00088
00089
00095 typedef int GLAttribute ;
00096
00097 }
00098
00099 }
00100
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 #if defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00112
00113 #include "OSDLConfigForNintendoDS.h"
00114
00115
00116
00117
00118
00119
00120
00121
00122 typedef Ceylan::Float32 GLfloat ;
00123
00124 #endif // on OSDL_ARCH_NINTENDO_DS
00125
00126
00127 #endif // OSDL_USES_SDL not available
00128
00129
00130
00131 #include <string>
00132
00133
00134
00135
00136
00137 namespace OSDL
00138 {
00139
00140
00141
00142 namespace Video
00143 {
00144
00145
00146
00147
00160 namespace OpenGL
00161 {
00162
00163
00164
00165
00167 class OSDL_DLL OpenGLException : public VideoException
00168 {
00169
00170 public:
00171
00172
00174 OpenGLException( const std::string & reason ) ;
00175
00176
00178 virtual ~OpenGLException() throw() ;
00179
00180 } ;
00181
00182
00183
00184
00190 extern OSDL_DLL Pixels::ColorMask RedMask ;
00191
00192
00193
00199 extern OSDL_DLL Pixels::ColorMask GreenMask ;
00200
00201
00202
00208 extern OSDL_DLL Pixels::ColorMask BlueMask ;
00209
00210
00211
00217 extern OSDL_DLL Pixels::ColorMask AlphaMask ;
00218
00219
00220
00226 typedef GLfloat GLLength ;
00227
00228
00229
00235 typedef GLfloat GLCoordinate ;
00236
00237
00238
00246 typedef unsigned int GLBitField ;
00247
00248
00249
00257 typedef unsigned int GLEnumeration ;
00258
00259
00260
00284 enum Flavour { None, OpenGLFor2D, OpenGLFor3D, Reload } ;
00285
00286
00287
00288
00293 enum Feature {
00294
00295
00296
00297
00298
00299
00300 Alphablending = GL_BLEND,
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 TwoDimensionalTexturing = GL_TEXTURE_2D,
00311
00312
00313
00314
00315
00316
00317
00318 CullPolygons = GL_CULL_FACE,
00319
00320
00321
00322
00323
00324
00325
00326 DepthTests = GL_DEPTH_TEST,
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 Lighting = GL_LIGHTING,
00343
00344
00345
00346
00347
00348
00349
00350 Light_1 = GL_LIGHT0,
00351
00352
00353
00354
00355
00356
00357
00358 Light_2 = GL_LIGHT1,
00359
00360
00361
00362
00363
00364
00365
00366 Light_3 = GL_LIGHT2,
00367
00368
00369
00370
00371
00372
00373
00374 Light_4 = GL_LIGHT3,
00375
00376
00377
00378
00379
00380
00381
00382 Light_5 = GL_LIGHT4,
00383
00384
00385
00386
00387
00388
00389
00390 Light_6 = GL_LIGHT5,
00391
00392
00393
00394
00395
00396
00397
00398 Light_7 = GL_LIGHT6,
00399
00400
00401
00402
00403
00404
00405
00406 Light_8 = GL_LIGHT7
00407
00408
00409 } ;
00410
00411
00412
00413
00428 class OSDL_DLL OpenGLContext : public Ceylan::TextDisplayable
00429 {
00430
00431
00432
00433 public:
00434
00435
00436
00445 enum ProjectionMode { Orthographic, Perspective } ;
00446
00447
00448
00468 enum ShadingModel { Flat, Smooth } ;
00469
00470
00471
00491 enum CulledFacet { Front, Back, FrontAndBack } ;
00492
00493
00494
00513 enum FrontOrientation { Clockwise, CounterClockwise } ;
00514
00515
00516
00538 OpenGLContext( OpenGL::Flavour flavour,
00539 BitsPerPixel plannedBpp,
00540 Length viewportWidth,
00541 Length viewportHeight ) ;
00542
00543
00544
00546 virtual ~OpenGLContext() throw() ;
00547
00548
00549
00566 virtual void selectFlavour( OpenGL::Flavour flavour ) ;
00567
00568
00569
00585 virtual void set2DFlavour() ;
00586
00587
00588
00601 virtual void set3DFlavour() ;
00602
00603
00604
00615 virtual void blank() ;
00616
00617
00618
00632 virtual void reload() ;
00633
00634
00635
00649 virtual void setBlendingFunction(
00650 GLEnumeration sourceFactor,
00651 GLEnumeration destinationFactor ) ;
00652
00653
00654
00664 virtual void setShadingModel(
00665 ShadingModel newShadingModel = Smooth ) ;
00666
00667
00668
00678 virtual void setCullingStatus( bool newStatus ) ;
00679
00680
00681
00697 virtual void setCulling( CulledFacet culledFacet = Back,
00698 FrontOrientation frontOrientation = CounterClockwise,
00699 bool autoEnable = true ) ;
00700
00701
00702
00712 virtual void setDepthBufferStatus( bool newStatus ) ;
00713
00714
00715
00716
00717
00718
00719
00720
00721
00746 virtual void setViewPort( Length width, Length height,
00747 const TwoDimensional::Point2D & lowerLeftCorner =
00748 TwoDimensional::Point2D::Origin ) ;
00749
00750
00751
00784 virtual void setOrthographicProjection( GLLength width,
00785 GLCoordinate near = -DefaultNearClippingPlaneFor3D,
00786 GLCoordinate far = -DefaultFarClippingPlaneFor3D ) ;
00787
00788
00789
00804 virtual void setOrthographicProjectionFor2D(
00805 GLLength width, GLLength height ) ;
00806
00807
00808
00817 virtual void setClearColor(
00818 const Video::Pixels::ColorDefinition & color ) ;
00819
00820
00821
00834 virtual void clearViewport() ;
00835
00836
00837
00848 virtual void clearDepthBuffer() ;
00849
00850
00851
00859 virtual void pushAttribute( GLBitField attributeField ) ;
00860
00861
00862
00870 virtual void popAttribute() ;
00871
00872
00873
00904 virtual const std::string toString(
00905 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00940 static void SetUpForFlavour( OpenGL::Flavour flavour,
00941 bool safest = false ) ;
00942
00943
00944
00953 static void EnableFeature( OpenGL::Feature feature ) ;
00954
00955
00956
00965 static void DisableFeature( OpenGL::Feature feature ) ;
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00988 static bool GetDoubleBufferStatus() ;
00989
00990
00991
01005 static void SetDoubleBufferStatus( bool newStatus ) ;
01006
01007
01008
01015 static Ceylan::Uint8 GetDepthBufferSize() ;
01016
01017
01018
01033 static void SetDepthBufferSize(
01034 Ceylan::Uint8 bitsNumber = 16 ) ;
01035
01036
01037
01051 static Ceylan::Uint8 GetFullScreenAntialiasingStatus() ;
01052
01053
01054
01074 static void SetFullScreenAntialiasingStatus(
01075 bool newStatus,
01076 Ceylan::Uint8 samplesPerPixelNumber = 4 ) ;
01077
01078
01079
01090 static bool GetHardwareAccelerationStatus() ;
01091
01092
01093
01111 static void SetHardwareAccelerationStatus(
01112 bool newStatus ) ;
01113
01114
01115
01125 static bool GetVerticalBlankSynchronizationStatus() ;
01126
01127
01128
01142 static void SetVerticalBlankSynchronizationStatus(
01143 bool newStatus ) ;
01144
01145
01146
01164 static bool TrySettingVerticalBlankSynchronizationStatus(
01165 bool newStatus ) ;
01166
01167
01168
01189 static OSDL::Video::BitsPerPixel GetColorDepth(
01190 OSDL::Video::BitsPerPixel & redSize,
01191 OSDL::Video::BitsPerPixel & greenSize,
01192 OSDL::Video::BitsPerPixel & blueSize,
01193 OSDL::Video::BitsPerPixel & alphaSize ) ;
01194
01195
01196
01209 static void SetColorDepth(
01210 OSDL::Video::BitsPerPixel plannedBpp ) ;
01211
01212
01213
01234 static void SetColorDepth(
01235 OSDL::Video::BitsPerPixel redSize,
01236 OSDL::Video::BitsPerPixel greenSize,
01237 OSDL::Video::BitsPerPixel blueSize ) ;
01238
01239
01240
01252 static std::string InterpretFeatureAvailability() ;
01253
01254
01255
01263 static std::string ToString( OpenGL::Flavour flavour ) ;
01264
01265
01266
01267
01268
01269
01270
01271
01272
01282 static const bool ContextCanBeLost ;
01283
01284
01285
01293 static const bool ContextIsLostOnResize ;
01294
01295
01296
01304 static const bool ContextIsLostOnApplicationSwitch ;
01305
01306
01307
01316 static const bool ContextIsLostOnColorDepthChange ;
01317
01318
01319
01320
01326 static const GLLength DefaultOrthographicWidth ;
01327
01328
01329
01335 static const GLCoordinate DefaultNearClippingPlaneFor2D ;
01336
01337
01338
01344 static const GLCoordinate DefaultFarClippingPlaneFor2D ;
01345
01346
01347
01353 static const GLCoordinate DefaultNearClippingPlaneFor3D ;
01354
01355
01356
01362 static const GLCoordinate DefaultFarClippingPlaneFor3D ;
01363
01364
01365
01366
01367
01368 protected:
01369
01370
01371
01380 virtual void updateProjection() ;
01381
01382
01383
01397 static bool HasGLAttribute( GLAttribute attribute ) ;
01398
01399
01400
01413 static int GetGLAttribute( GLAttribute attribute ) ;
01414
01415
01416
01430 static void SetGLAttribute( GLAttribute attribute,
01431 int value ) ;
01432
01433
01434
01450 static bool TrySettingGLAttribute( GLAttribute attribute,
01451 int value ) ;
01452
01453
01454
01464 static std::string GLAttributeToString(
01465 GLAttribute attribute ) ;
01466
01467
01468
01469
01470
01471
01472
01473
01474
01476 OpenGL::Flavour _flavour ;
01477
01478
01479
01481 OSDL::Video::BitsPerPixel _redSize ;
01482
01483
01484
01486 OSDL::Video::BitsPerPixel _greenSize ;
01487
01488
01489
01491 OSDL::Video::BitsPerPixel _blueSize ;
01492
01493
01494
01496 OSDL::Video::BitsPerPixel _alphaSize ;
01497
01498
01499
01505 Length _viewportWidth ;
01506
01507
01508
01514 Length _viewportHeight ;
01515
01516
01517
01519 ProjectionMode _projectionMode ;
01520
01521
01522
01529 GLLength _projectionWidth ;
01530
01531
01532
01538 GLCoordinate _nearClippingPlane ;
01539
01540
01541
01543 GLCoordinate _farClippingPlane ;
01544
01545
01546
01553 Pixels::ColorDefinition _clearColor ;
01554
01555
01556
01557
01558 private:
01559
01560
01561
01570 OpenGLContext( const OpenGLContext & source ) ;
01571
01572
01573
01582 OpenGLContext & operator = ( const OpenGLContext & source );
01583
01584
01585 } ;
01586
01587
01588
01589
01607 namespace GLU
01608 {
01609
01611 typedef Ceylan::Uint32 Int ;
01612
01613 }
01614
01615
01616
01617 }
01618
01619 }
01620
01621 }
01622
01623
01624
01625 #endif // OSDL_OPENGL_H_
01626