John Fay: Implement the modified logic of the direct/indirect rendering context.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@501 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
puggles 2004-05-12 00:29:27 +00:00
parent c28e19b830
commit ae113a8850
4 changed files with 63 additions and 53 deletions

View File

@ -59,8 +59,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
{ 300, 300, GL_TRUE }, /* Size */ { 300, 300, GL_TRUE }, /* Size */
GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */ GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */
GL_FALSE, /* Initialised */ GL_FALSE, /* Initialised */
GL_FALSE, /* ForceDirectContext */ GLUT_TRY_DIRECT_CONTEXT, /* DirectContext */
GL_TRUE, /* TryDirectContext */
GL_FALSE, /* ForceIconic */ GL_FALSE, /* ForceIconic */
GL_FALSE, /* UseCurrentContext */ GL_FALSE, /* UseCurrentContext */
GL_FALSE, /* GLDebugSwitch */ GL_FALSE, /* GLDebugSwitch */
@ -273,8 +272,7 @@ void fgDeinitialize( void )
fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH;
fgState.ForceDirectContext = GL_FALSE; fgState.DirectContext = GLUT_TRY_DIRECT_CONTEXT;
fgState.TryDirectContext = GL_TRUE;
fgState.ForceIconic = GL_FALSE; fgState.ForceIconic = GL_FALSE;
fgState.UseCurrentContext = GL_FALSE; fgState.UseCurrentContext = GL_FALSE;
fgState.GLDebugSwitch = GL_FALSE; fgState.GLDebugSwitch = GL_FALSE;
@ -570,21 +568,21 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
} }
else if( strcmp( argv[ i ], "-direct" ) == 0) else if( strcmp( argv[ i ], "-direct" ) == 0)
{ {
if( ! fgState.TryDirectContext ) if( fgState.DirectContext == GLUT_FORCE_INDIRECT_CONTEXT )
fgError( "parameters ambiguity, -direct and -indirect " fgError( "parameters ambiguity, -direct and -indirect "
"cannot be both specified" ); "cannot be both specified" );
fgState.ForceDirectContext = GL_TRUE; fgState.DirectContext = GLUT_FORCE_DIRECT_CONTEXT;
argv[ i ] = NULL; argv[ i ] = NULL;
( *pargc )--; ( *pargc )--;
} }
else if( strcmp( argv[ i ], "-indirect" ) == 0 ) else if( strcmp( argv[ i ], "-indirect" ) == 0 )
{ {
if( fgState.ForceDirectContext ) if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
fgError( "parameters ambiguity, -direct and -indirect " fgError( "parameters ambiguity, -direct and -indirect "
"cannot be both specified" ); "cannot be both specified" );
fgState.TryDirectContext = GL_FALSE; fgState.DirectContext = GLUT_FORCE_INDIRECT_CONTEXT;
argv[ i ] = NULL; argv[ i ] = NULL;
(*pargc)--; (*pargc)--;
} }

View File

@ -222,8 +222,7 @@ struct tagSFG_State
GLboolean Initialised; /* freeglut has been initialised */ GLboolean Initialised; /* freeglut has been initialised */
GLboolean ForceDirectContext; /* Force direct rendering? */ int DirectContext; /* Direct rendering state */
GLboolean TryDirectContext; /* What about giving a try to? */
GLboolean ForceIconic; /* New top windows are iconified */ GLboolean ForceIconic; /* New top windows are iconified */
GLboolean UseCurrentContext; /* New windows share with current */ GLboolean UseCurrentContext; /* New windows share with current */

View File

@ -72,51 +72,55 @@ static int fghGetConfig( int attribute )
*/ */
void FGAPIENTRY glutSetOption( GLenum eWhat, int value ) void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
{ {
freeglut_assert_ready; freeglut_assert_ready;
/* /*
* XXX In chronological code add order. (WHY in that order?) * XXX In chronological code add order. (WHY in that order?)
*/ */
switch( eWhat ) switch( eWhat )
{ {
case GLUT_INIT_WINDOW_X: case GLUT_INIT_WINDOW_X:
fgState.Position.X = (GLint)value; fgState.Position.X = (GLint)value;
break; break;
case GLUT_INIT_WINDOW_Y: case GLUT_INIT_WINDOW_Y:
fgState.Position.Y = (GLint)value; fgState.Position.Y = (GLint)value;
break; break;
case GLUT_INIT_WINDOW_WIDTH: case GLUT_INIT_WINDOW_WIDTH:
fgState.Size.X = (GLint)value; fgState.Size.X = (GLint)value;
break; break;
case GLUT_INIT_WINDOW_HEIGHT: case GLUT_INIT_WINDOW_HEIGHT:
fgState.Size.Y = (GLint)value; fgState.Size.Y = (GLint)value;
break; break;
case GLUT_INIT_DISPLAY_MODE: case GLUT_INIT_DISPLAY_MODE:
fgState.DisplayMode = (unsigned int)value; fgState.DisplayMode = (unsigned int)value;
break; break;
case GLUT_ACTION_ON_WINDOW_CLOSE: case GLUT_ACTION_ON_WINDOW_CLOSE:
fgState.ActionOnWindowClose = value; fgState.ActionOnWindowClose = value;
break; break;
case GLUT_RENDERING_CONTEXT: case GLUT_RENDERING_CONTEXT:
fgState.UseCurrentContext = fgState.UseCurrentContext =
( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE; ( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
break; break;
case GLUT_WINDOW_CURSOR: case GLUT_DIRECT_RENDERING:
if( fgStructure.Window != NULL ) fgState.DirectContext = value;
fgStructure.Window->State.Cursor = value; break;
break;
default: case GLUT_WINDOW_CURSOR:
fgWarning( "glutSetOption(): missing enum handle %i\n", eWhat ); if( fgStructure.Window != NULL )
break; fgStructure.Window->State.Cursor = value;
} break;
default:
fgWarning( "glutSetOption(): missing enum handle %i\n", eWhat );
break;
}
} }
/* /*
@ -463,6 +467,10 @@ int FGAPIENTRY glutGet( GLenum eWhat )
return fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT return fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT
: GLUT_CREATE_NEW_CONTEXT; : GLUT_CREATE_NEW_CONTEXT;
case GLUT_DIRECT_RENDERING:
return fgState.DirectContext;
break;
default: default:
fgWarning( "glutGet(): missing enum handle %i\n", eWhat ); fgWarning( "glutGet(): missing enum handle %i\n", eWhat );
break; break;

View File

@ -389,14 +389,14 @@ void fgOpenWindow( SFG_Window* window, const char* title,
fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo; fgStructure.MenuContext->VisualInfo = window->Window.VisualInfo;
fgStructure.MenuContext->Context = glXCreateContext( fgStructure.MenuContext->Context = glXCreateContext(
fgDisplay.Display, fgStructure.MenuContext->VisualInfo, fgDisplay.Display, fgStructure.MenuContext->VisualInfo,
NULL, fgState.ForceDirectContext | fgState.TryDirectContext NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
); );
} }
/* window->Window.Context = fgStructure.MenuContext->Context; */ /* window->Window.Context = fgStructure.MenuContext->Context; */
window->Window.Context = glXCreateContext( window->Window.Context = glXCreateContext(
fgDisplay.Display, window->Window.VisualInfo, fgDisplay.Display, window->Window.VisualInfo,
NULL, fgState.ForceDirectContext | fgState.TryDirectContext NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
); );
} }
else if( fgState.UseCurrentContext ) else if( fgState.UseCurrentContext )
@ -406,19 +406,24 @@ void fgOpenWindow( SFG_Window* window, const char* title,
if( ! window->Window.Context ) if( ! window->Window.Context )
window->Window.Context = glXCreateContext( window->Window.Context = glXCreateContext(
fgDisplay.Display, window->Window.VisualInfo, fgDisplay.Display, window->Window.VisualInfo,
NULL, fgState.ForceDirectContext | fgState.TryDirectContext NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
); );
} }
else else
window->Window.Context = glXCreateContext( window->Window.Context = glXCreateContext(
fgDisplay.Display, window->Window.VisualInfo, fgDisplay.Display, window->Window.VisualInfo,
NULL, fgState.ForceDirectContext | fgState.TryDirectContext NULL, ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT )
); );
if( fgState.ForceDirectContext && if( !glXIsDirect( fgDisplay.Display, window->Window.Context ) )
!glXIsDirect( fgDisplay.Display, window->Window.Context ) ) {
fgError( "unable to force direct context rendering for window '%s'", if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
fgError( "Unable to force direct context rendering for window '%s'",
title ); title );
else if( fgState.DirectContext == GLUT_TRY_DIRECT_CONTEXT )
fgWarning( "Unable to create direct context rendering for window '%s'\nThis may hurt performance.",
title );
}
glXMakeCurrent( glXMakeCurrent(
fgDisplay.Display, fgDisplay.Display,