2015-04-08 02:01:12 +08:00
/* OpenSceneGraph example, osgmemorytest.
2008-11-11 04:06:27 +08:00
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the " Software " ) , to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE .
*/
# include <osg/Notify>
2008-11-12 18:30:17 +08:00
# include <osg/Timer>
2008-11-11 04:06:27 +08:00
# include <osg/ArgumentParser>
# include <osg/Texture1D>
# include <osg/Texture2D>
# include <osg/Texture3D>
2008-11-12 00:13:37 +08:00
# include <osg/Geometry>
2008-11-12 18:30:17 +08:00
# include <osg/FrameBufferObject>
2008-11-11 04:06:27 +08:00
2008-11-12 18:30:17 +08:00
# include <osgViewer/Version>
2008-11-11 04:06:27 +08:00
2008-11-11 23:00:29 +08:00
# include <stdio.h>
2008-11-12 00:59:58 +08:00
# include <iostream>
2008-11-11 23:00:29 +08:00
2008-11-11 04:06:27 +08:00
class MemoryTest : public osg : : Referenced
{
public :
} ;
2008-11-11 20:50:51 +08:00
class GLObject : public osg : : Referenced
2008-11-11 04:06:27 +08:00
{
public :
2008-11-12 00:13:37 +08:00
virtual void apply ( osg : : RenderInfo & renderInfo ) = 0 ;
2008-11-11 04:06:27 +08:00
} ;
2008-11-11 20:50:51 +08:00
class GLMemoryTest : public MemoryTest
2008-11-11 04:06:27 +08:00
{
public :
2008-11-11 20:50:51 +08:00
virtual GLObject * allocate ( ) = 0 ;
2008-11-11 04:06:27 +08:00
} ;
/////////////////////////////////////////////////////////////////////////
//
2008-11-11 20:50:51 +08:00
// Context test
class ContextTest : public MemoryTest
2008-11-11 04:06:27 +08:00
{
public :
2008-11-11 20:50:51 +08:00
ContextTest ( int width , int height , bool pbuffer ) :
2008-11-11 04:06:27 +08:00
_width ( width ) ,
2008-11-11 20:50:51 +08:00
_height ( height ) ,
_pbuffer ( pbuffer ) { }
2008-11-11 04:06:27 +08:00
virtual osg : : GraphicsContext * allocate ( )
{
osg : : ref_ptr < osg : : GraphicsContext : : Traits > traits = new osg : : GraphicsContext : : Traits ;
traits - > width = _width ;
traits - > height = _height ;
2008-11-11 20:50:51 +08:00
traits - > windowDecoration = true ;
traits - > pbuffer = _pbuffer ;
2008-11-11 04:06:27 +08:00
2008-11-11 20:50:51 +08:00
osg : : ref_ptr < osg : : GraphicsContext > window = osg : : GraphicsContext : : createGraphicsContext ( traits . get ( ) ) ;
if ( window . valid ( ) )
2008-11-11 04:06:27 +08:00
{
2008-11-11 20:50:51 +08:00
if ( window - > realize ( ) )
2008-11-11 04:06:27 +08:00
{
2008-11-11 20:50:51 +08:00
return window . release ( ) ;
2008-11-11 04:06:27 +08:00
}
else
{
2008-11-11 20:50:51 +08:00
if ( _pbuffer ) throw " Failed to realize PixelBuffer " ;
else throw " Failed to realize GraphicsWindow " ;
2008-11-11 04:06:27 +08:00
}
}
else
{
2009-02-06 23:17:49 +08:00
std : : cerr < < " Error: Unable to create graphics context, problem with running osgViewer- " < < osgViewerGetVersion ( ) < < " , cannot create windows/pbuffers. " < < std : : endl ;
2008-11-12 18:30:17 +08:00
2008-11-11 20:50:51 +08:00
if ( _pbuffer ) throw " Failed to create PixelBuffer " ;
else throw " Failed to create GraphicsWindow " ;
2008-11-11 04:06:27 +08:00
}
}
protected :
int _width ;
int _height ;
2008-11-11 20:50:51 +08:00
bool _pbuffer ;
2008-11-11 04:06:27 +08:00
} ;
2008-11-11 20:50:51 +08:00
////////////////////////////////////////////////////////////////////////
2008-11-11 04:06:27 +08:00
//
2008-11-11 20:50:51 +08:00
// Wrap StateAttribute
class StateAttributeObject : public GLObject
2008-11-11 04:06:27 +08:00
{
public :
2008-11-11 20:50:51 +08:00
StateAttributeObject ( osg : : StateAttribute * sa ) : _attribute ( sa ) { }
2008-11-11 04:06:27 +08:00
2008-11-12 00:13:37 +08:00
void apply ( osg : : RenderInfo & renderInfo )
2008-11-11 04:06:27 +08:00
{
2008-11-12 00:13:37 +08:00
_attribute - > apply ( * renderInfo . getState ( ) ) ;
2008-11-11 04:06:27 +08:00
2008-11-12 00:13:37 +08:00
if ( renderInfo . getState ( ) - > checkGLErrors ( _attribute . get ( ) ) )
2008-11-11 04:06:27 +08:00
{
2008-11-11 20:50:51 +08:00
throw " OpenGL error " ;
2008-11-11 04:06:27 +08:00
}
}
2008-11-11 20:50:51 +08:00
osg : : ref_ptr < osg : : StateAttribute > _attribute ;
2008-11-11 04:06:27 +08:00
} ;
/////////////////////////////////////////////////////////////////////////
//
2008-11-11 20:50:51 +08:00
// Texture test
2008-11-11 04:06:27 +08:00
class TextureTest : public GLMemoryTest
{
public :
2008-11-11 20:50:51 +08:00
2008-11-12 00:13:37 +08:00
TextureTest ( int width = 256 , int height = 256 , int depth = 1 ) :
2008-11-11 04:06:27 +08:00
_width ( width ) ,
_height ( height ) ,
_depth ( depth ) { }
2008-11-11 20:50:51 +08:00
virtual GLObject * allocate ( )
2008-11-11 04:06:27 +08:00
{
if ( _depth > 1 )
{
osg : : ref_ptr < osg : : Image > image = new osg : : Image ;
image - > allocateImage ( _width , _height , _depth , GL_RGBA , GL_UNSIGNED_BYTE ) ;
osg : : ref_ptr < osg : : Texture3D > texture = new osg : : Texture3D ;
texture - > setImage ( image . get ( ) ) ;
2008-11-11 20:50:51 +08:00
texture - > setResizeNonPowerOfTwoHint ( false ) ;
2008-11-11 04:06:27 +08:00
2008-11-11 20:50:51 +08:00
return new StateAttributeObject ( texture . get ( ) ) ;
2008-11-11 04:06:27 +08:00
}
if ( _height > 1 )
{
osg : : ref_ptr < osg : : Image > image = new osg : : Image ;
image - > allocateImage ( _width , _height , 1 , GL_RGBA , GL_UNSIGNED_BYTE ) ;
osg : : ref_ptr < osg : : Texture2D > texture = new osg : : Texture2D ;
texture - > setImage ( image . get ( ) ) ;
2008-11-11 20:50:51 +08:00
texture - > setResizeNonPowerOfTwoHint ( false ) ;
2008-11-11 04:06:27 +08:00
2008-11-11 20:50:51 +08:00
return new StateAttributeObject ( texture . get ( ) ) ;
2008-11-11 04:06:27 +08:00
}
if ( _width > 1 )
{
osg : : ref_ptr < osg : : Image > image = new osg : : Image ;
image - > allocateImage ( _width , 1 , 1 , GL_RGBA , GL_UNSIGNED_BYTE ) ;
osg : : ref_ptr < osg : : Texture1D > texture = new osg : : Texture1D ;
texture - > setImage ( image . get ( ) ) ;
2008-11-11 20:50:51 +08:00
texture - > setResizeNonPowerOfTwoHint ( false ) ;
2008-11-11 04:06:27 +08:00
2008-11-11 20:50:51 +08:00
return new StateAttributeObject ( texture . get ( ) ) ;
2008-11-11 04:06:27 +08:00
}
else
{
2008-11-11 20:50:51 +08:00
throw " Invalid texture size of 0,0,0 " ;
2008-11-11 04:06:27 +08:00
}
}
protected :
2008-11-11 20:50:51 +08:00
int _width ;
int _height ;
int _depth ;
} ;
2008-11-12 00:13:37 +08:00
2008-11-11 20:50:51 +08:00
/////////////////////////////////////////////////////////////////////////
//
2008-11-12 00:13:37 +08:00
// FrameBufferObject test
2008-11-11 20:50:51 +08:00
class FboTest : public GLMemoryTest
{
public :
FboTest ( int width = 1024 , int height = 1024 , int depth = 2 ) :
_width ( width ) ,
_height ( height ) ,
_depth ( depth ) { }
virtual GLObject * allocate ( )
2008-11-11 04:06:27 +08:00
{
2008-11-11 20:50:51 +08:00
osg : : ref_ptr < osg : : FrameBufferObject > fbo = new osg : : FrameBufferObject ;
if ( _depth > = 1 ) fbo - > setAttachment ( osg : : Camera : : COLOR_BUFFER , osg : : FrameBufferAttachment ( new osg : : RenderBuffer ( _width , _height , GL_RGBA ) ) ) ;
if ( _depth > = 2 ) fbo - > setAttachment ( osg : : Camera : : DEPTH_BUFFER , osg : : FrameBufferAttachment ( new osg : : RenderBuffer ( _width , _height , GL_DEPTH_COMPONENT24 ) ) ) ;
return new StateAttributeObject ( fbo . get ( ) ) ;
2008-11-11 04:06:27 +08:00
}
2008-11-11 20:50:51 +08:00
protected :
2008-11-11 04:06:27 +08:00
int _width ;
int _height ;
int _depth ;
} ;
2008-11-12 00:13:37 +08:00
////////////////////////////////////////////////////////////////////////
//
// Wrap Drawable
class DrawableObject : public GLObject
{
public :
DrawableObject ( osg : : Drawable * drawable ) : _drawable ( drawable ) { }
void apply ( osg : : RenderInfo & renderInfo )
{
_drawable - > draw ( renderInfo ) ;
if ( renderInfo . getState ( ) - > checkGLErrors ( " Drawable " ) )
{
throw " OpenGL error " ;
}
}
osg : : ref_ptr < osg : : Drawable > _drawable ;
} ;
/////////////////////////////////////////////////////////////////////////
//
// Geometry test
class GeometryTest : public GLMemoryTest
{
public :
enum GLObjectType
{
VERTEX_ARRAY ,
DISPLAY_LIST ,
VERTEX_BUFFER_OBJECT
} ;
GeometryTest ( GLObjectType type , int width = 64 , int height = 64 ) :
_glObjectType ( type ) ,
_width ( width ) ,
_height ( height ) { }
virtual GLObject * allocate ( )
{
unsigned int numVertices = _width * _height ;
osg : : Vec3Array * vertices = new osg : : Vec3Array ( numVertices ) ;
2008-12-18 21:56:30 +08:00
for ( int j = 0 ; j < _height ; + + j )
2008-11-12 00:13:37 +08:00
{
2008-12-18 21:56:30 +08:00
for ( int i = 0 ; i < _width ; + + i )
2008-11-12 00:13:37 +08:00
{
( * vertices ) [ i + j * _width ] . set ( float ( i ) , float ( j ) , 0.0f ) ;
}
}
unsigned int numIndices = ( _width - 1 ) * ( _height - 1 ) * 4 ;
osg : : DrawElementsUShort * quads = new osg : : DrawElementsUShort ( GL_QUADS ) ;
quads - > reserve ( numIndices ) ;
2008-12-18 21:56:30 +08:00
for ( int j = 0 ; j < _height - 1 ; + + j )
2008-11-12 00:13:37 +08:00
{
2008-12-18 21:56:30 +08:00
for ( int i = 0 ; i < _width - 1 ; + + i )
2008-11-12 00:13:37 +08:00
{
quads - > push_back ( i + j * _width ) ;
quads - > push_back ( i + 1 + j * _width ) ;
quads - > push_back ( i + 1 + ( j + 1 ) * _width ) ;
quads - > push_back ( i + ( j + 1 ) * _width ) ;
}
}
osg : : Geometry * geometry = new osg : : Geometry ;
geometry - > setVertexArray ( vertices ) ;
geometry - > addPrimitiveSet ( quads ) ;
switch ( _glObjectType )
{
case ( VERTEX_ARRAY ) :
geometry - > setUseDisplayList ( false ) ;
geometry - > setUseVertexBufferObjects ( false ) ;
break ;
case ( DISPLAY_LIST ) :
geometry - > setUseDisplayList ( true ) ;
geometry - > setUseVertexBufferObjects ( false ) ;
break ;
case ( VERTEX_BUFFER_OBJECT ) :
geometry - > setUseDisplayList ( false ) ;
geometry - > setUseVertexBufferObjects ( true ) ;
break ;
}
return new DrawableObject ( geometry ) ;
}
protected :
GLObjectType _glObjectType ;
int _width ;
int _height ;
} ;
2008-11-11 04:06:27 +08:00
int main ( int argc , char * * argv )
{
osg : : ArgumentParser arguments ( & argc , argv ) ;
2008-11-12 00:59:58 +08:00
arguments . getApplicationUsage ( ) - > setApplicationName ( arguments . getApplicationName ( ) ) ;
arguments . getApplicationUsage ( ) - > setDescription ( arguments . getApplicationName ( ) + " tests OpenGL and Windowing memory scalability.. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -h or --help " , " List command line options. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --pbuffer " , " Create a 512x512 pixel buffer. " ) ;
2008-11-12 01:29:48 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --pbuffer <width> <height> " , " Create a pixel buffer of specified dimensions. " ) ;
2008-11-12 00:59:58 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --window " , " Create a 512x512 graphics window. " ) ;
2008-11-12 01:29:48 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --window <width> <height> " , " Create a graphics window of specified dimensions. " ) ;
2008-11-12 00:59:58 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --delay <micoseconds> " , " Set a delay in microseconds before all OpenGL object operations. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --texture <width> <height> <depth> " , " Allocate a 3D texture of specified dimensions. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --texture <width> <height> " , " Allocate a 2D texture of specified dimensions. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --texture <width> " , " Allocate a 1D texture of specified dimensions. " ) ;
2018-04-21 00:18:22 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --geometry <width> <height> " , " Allocate a osg::Geometry representing a grid of specified size, using OpenGL Display Lists. " ) ;
2008-11-12 00:59:58 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --geometry-va <width> <height> " , " Allocate a osg::Geometry representing a grid of specified size, using Vertex Arrays. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --geometry-vbo <width> <height> " , " Allocate a osg::Geometry representing a grid of specified size, using Vertex Buffer Objects. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --fbo <width> <height> " , " Allocate a FrameBufferObject of specified dimensions. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -c <num> " , " Set the number of contexts to create of each type specified. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -g <num> " , " Set the number of GL objects to create of each type specified. " ) ;
if ( arguments . read ( " -h " ) | | arguments . read ( " --help " ) )
{
arguments . getApplicationUsage ( ) - > write ( std : : cout , osg : : ApplicationUsage : : COMMAND_LINE_OPTION ) ;
return 1 ;
}
2008-11-12 01:29:48 +08:00
2008-11-12 00:59:58 +08:00
if ( arguments . argc ( ) < = 1 )
{
arguments . getApplicationUsage ( ) - > write ( std : : cout , osg : : ApplicationUsage : : COMMAND_LINE_OPTION ) ;
return 1 ;
}
typedef std : : list < osg : : ref_ptr < GLMemoryTest > > GLMemoryTests ;
typedef std : : list < osg : : ref_ptr < ContextTest > > ContextTests ;
ContextTests contextTests ;
GLMemoryTests glMemoryTests ;
2008-11-11 04:06:27 +08:00
int width , height , depth ;
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --pbuffer " , width , height ) ) { contextTests . push_back ( new ContextTest ( width , height , true ) ) ; }
while ( arguments . read ( " --pbuffer " ) ) { contextTests . push_back ( new ContextTest ( 512 , 512 , true ) ) ; }
2008-11-11 04:06:27 +08:00
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --window " , width , height ) ) { contextTests . push_back ( new ContextTest ( width , height , false ) ) ; }
while ( arguments . read ( " --window " ) ) { contextTests . push_back ( new ContextTest ( 512 , 512 , false ) ) ; }
2008-11-11 04:06:27 +08:00
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --texture " , width , height , depth ) ) { glMemoryTests . push_back ( new TextureTest ( width , height , depth ) ) ; }
while ( arguments . read ( " --texture " , width , height ) ) { glMemoryTests . push_back ( new TextureTest ( width , height , 1 ) ) ; }
while ( arguments . read ( " --texture " , width ) ) { glMemoryTests . push_back ( new TextureTest ( width , 1 , 1 ) ) ; }
2008-11-11 04:06:27 +08:00
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --fbo " , width , height , depth ) ) { glMemoryTests . push_back ( new FboTest ( width , height , depth ) ) ; }
while ( arguments . read ( " --fbo " , width , height ) ) { glMemoryTests . push_back ( new FboTest ( width , height , 2 ) ) ; }
while ( arguments . read ( " --fbo " ) ) { glMemoryTests . push_back ( new FboTest ( 1024 , 1024 , 2 ) ) ; }
2008-11-11 20:50:51 +08:00
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --geometry " , width , height ) ) { glMemoryTests . push_back ( new GeometryTest ( GeometryTest : : DISPLAY_LIST , width , height ) ) ; }
while ( arguments . read ( " --geometry " ) ) { glMemoryTests . push_back ( new GeometryTest ( GeometryTest : : DISPLAY_LIST , 64 , 64 ) ) ; }
2008-11-12 00:13:37 +08:00
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --geometry-vbo " , width , height ) ) { glMemoryTests . push_back ( new GeometryTest ( GeometryTest : : VERTEX_BUFFER_OBJECT , width , height ) ) ; }
while ( arguments . read ( " --geometry-vbo " ) ) { glMemoryTests . push_back ( new GeometryTest ( GeometryTest : : VERTEX_BUFFER_OBJECT , 64 , 64 ) ) ; }
2008-11-12 00:13:37 +08:00
2008-11-12 00:59:58 +08:00
while ( arguments . read ( " --geometry-va " , width , height ) ) { glMemoryTests . push_back ( new GeometryTest ( GeometryTest : : VERTEX_ARRAY , width , height ) ) ; }
while ( arguments . read ( " --geometry-va " ) ) { glMemoryTests . push_back ( new GeometryTest ( GeometryTest : : VERTEX_ARRAY , 64 , 64 ) ) ; }
2008-11-12 00:13:37 +08:00
2008-11-11 23:00:29 +08:00
unsigned int sleepTime = 0 ;
while ( arguments . read ( " --delay " , sleepTime ) ) { }
2008-11-11 20:50:51 +08:00
int maxNumContextIterations = 1 ;
2008-11-11 04:06:27 +08:00
while ( arguments . read ( " -c " , maxNumContextIterations ) ) { }
int maxNumGLIterations = 1000 ;
while ( arguments . read ( " -g " , maxNumGLIterations ) ) { }
2008-11-12 01:29:48 +08:00
#if 0
2008-11-12 00:59:58 +08:00
// any option left unread are converted into errors to write out later.
arguments . reportRemainingOptionsAsUnrecognized ( ) ;
// report any errors if they have occurred when parsing the program arguments.
if ( arguments . errors ( ) )
2008-11-11 04:06:27 +08:00
{
2008-11-12 00:59:58 +08:00
arguments . writeErrorMessages ( std : : cout ) ;
return 1 ;
2008-11-11 04:06:27 +08:00
}
2008-11-12 01:29:48 +08:00
# endif
2008-11-12 00:59:58 +08:00
2008-11-11 04:06:27 +08:00
typedef std : : list < osg : : ref_ptr < osg : : GraphicsContext > > Contexts ;
2008-11-11 20:50:51 +08:00
typedef std : : list < osg : : ref_ptr < GLObject > > GLObjects ;
2008-11-11 04:06:27 +08:00
Contexts allocatedContexts ;
2008-11-11 20:50:51 +08:00
GLObjects glObjects ;
2008-11-12 01:29:48 +08:00
if ( contextTests . empty ( ) )
{
if ( glMemoryTests . empty ( ) )
{
2009-02-06 23:17:49 +08:00
std : : cout < < " No tests specified, please specify test using the command line options below. " < < std : : endl < < std : : endl ;
2008-11-12 01:29:48 +08:00
arguments . getApplicationUsage ( ) - > write ( std : : cout , osg : : ApplicationUsage : : COMMAND_LINE_OPTION ) ;
return 1 ;
}
else
{
contextTests . push_back ( new ContextTest ( 512 , 512 , false ) ) ;
}
}
2008-11-11 04:06:27 +08:00
2008-11-12 00:21:04 +08:00
osg : : Timer_t startTick = osg : : Timer : : instance ( ) - > tick ( ) ;
2008-11-12 01:30:11 +08:00
// use printf's below as C++'s ostream classes use more memory and are more likely to fail when everything
// goes wrong with memory allocations.
2008-11-11 04:06:27 +08:00
int numContextIterations = 0 ;
2008-11-11 20:50:51 +08:00
int numGLObjectIterations = 0 ;
int numGLObjectsApplied = 0 ;
2008-11-11 04:06:27 +08:00
try
{
2008-11-11 20:50:51 +08:00
for ( ; numGLObjectIterations < maxNumGLIterations ; + + numGLObjectIterations )
{
for ( GLMemoryTests : : iterator itr = glMemoryTests . begin ( ) ;
itr ! = glMemoryTests . end ( ) ;
+ + itr )
{
osg : : ref_ptr < GLObject > glObject = ( * itr ) - > allocate ( ) ;
if ( glObject . valid ( ) ) glObjects . push_back ( glObject . get ( ) ) ;
}
}
2008-11-11 04:06:27 +08:00
for ( ; numContextIterations < maxNumContextIterations ; + + numContextIterations )
{
2008-11-12 01:59:35 +08:00
printf ( " GraphicsContext %i \n " , numContextIterations ) ;
2008-11-11 04:06:27 +08:00
for ( ContextTests : : iterator itr = contextTests . begin ( ) ;
itr ! = contextTests . end ( ) ;
+ + itr )
{
osg : : ref_ptr < osg : : GraphicsContext > context = ( * itr ) - > allocate ( ) ;
if ( context . valid ( ) )
{
2008-11-11 20:50:51 +08:00
allocatedContexts . push_back ( context ) ;
2008-11-11 04:06:27 +08:00
context - > makeCurrent ( ) ;
2008-11-12 00:13:37 +08:00
osg : : RenderInfo renderInfo ;
renderInfo . setState ( context - > getState ( ) ) ;
2008-11-11 20:50:51 +08:00
for ( GLObjects : : iterator gitr = glObjects . begin ( ) ;
gitr ! = glObjects . end ( ) ;
+ + gitr )
{
2008-11-11 23:00:29 +08:00
if ( sleepTime > 0 ) OpenThreads : : Thread : : microSleep ( sleepTime ) ;
printf ( " %i " , numGLObjectsApplied ) ; fflush ( stdout ) ;
2008-11-12 00:13:37 +08:00
( * gitr ) - > apply ( renderInfo ) ;
2008-11-11 20:50:51 +08:00
+ + numGLObjectsApplied ;
}
context - > releaseContext ( ) ;
2008-11-12 01:59:35 +08:00
2008-11-11 23:00:29 +08:00
printf ( " \n \n " ) ; fflush ( stdout ) ;
2008-11-11 04:06:27 +08:00
}
}
}
}
catch ( const char * errorString )
{
2008-11-12 00:21:04 +08:00
printf ( " \n Exception caught, contexts completed = %i, gl objects successfully applied = %i, error = %s \n \n " , numContextIterations , numGLObjectsApplied , errorString ) ;
2008-11-11 04:06:27 +08:00
return 1 ;
}
catch ( . . . )
{
2008-11-12 00:21:04 +08:00
printf ( " \n Exception caught, contexts completed = %i, gl objects successfully applied = %i \n \n " , numContextIterations , numGLObjectsApplied ) ;
2008-11-11 04:06:27 +08:00
return 1 ;
}
2008-11-12 00:21:04 +08:00
osg : : Timer_t endTick = osg : : Timer : : instance ( ) - > tick ( ) ;
printf ( " \n Successful completion, contexts created = %i, gl objects applied = %i \n " , numContextIterations , numGLObjectsApplied ) ;
printf ( " Duration = %f seconds. \n \n " , osg : : Timer : : instance ( ) - > delta_s ( startTick , endTick ) ) ;
2008-11-11 04:06:27 +08:00
2008-11-12 00:21:04 +08:00
2008-11-11 04:06:27 +08:00
return 0 ;
}