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

View File

@ -222,8 +222,7 @@ struct tagSFG_State
GLboolean Initialised; /* freeglut has been initialised */
GLboolean ForceDirectContext; /* Force direct rendering? */
GLboolean TryDirectContext; /* What about giving a try to? */
int DirectContext; /* Direct rendering state */
GLboolean ForceIconic; /* New top windows are iconified */
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 )
{
freeglut_assert_ready;
freeglut_assert_ready;
/*
* XXX In chronological code add order. (WHY in that order?)
*/
switch( eWhat )
{
case GLUT_INIT_WINDOW_X:
fgState.Position.X = (GLint)value;
break;
/*
* XXX In chronological code add order. (WHY in that order?)
*/
switch( eWhat )
{
case GLUT_INIT_WINDOW_X:
fgState.Position.X = (GLint)value;
break;
case GLUT_INIT_WINDOW_Y:
fgState.Position.Y = (GLint)value;
break;
case GLUT_INIT_WINDOW_Y:
fgState.Position.Y = (GLint)value;
break;
case GLUT_INIT_WINDOW_WIDTH:
fgState.Size.X = (GLint)value;
break;
case GLUT_INIT_WINDOW_WIDTH:
fgState.Size.X = (GLint)value;
break;
case GLUT_INIT_WINDOW_HEIGHT:
fgState.Size.Y = (GLint)value;
break;
case GLUT_INIT_WINDOW_HEIGHT:
fgState.Size.Y = (GLint)value;
break;
case GLUT_INIT_DISPLAY_MODE:
fgState.DisplayMode = (unsigned int)value;
break;
case GLUT_INIT_DISPLAY_MODE:
fgState.DisplayMode = (unsigned int)value;
break;
case GLUT_ACTION_ON_WINDOW_CLOSE:
fgState.ActionOnWindowClose = value;
break;
case GLUT_ACTION_ON_WINDOW_CLOSE:
fgState.ActionOnWindowClose = value;
break;
case GLUT_RENDERING_CONTEXT:
fgState.UseCurrentContext =
( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
break;
case GLUT_RENDERING_CONTEXT:
fgState.UseCurrentContext =
( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
break;
case GLUT_WINDOW_CURSOR:
if( fgStructure.Window != NULL )
fgStructure.Window->State.Cursor = value;
break;
case GLUT_DIRECT_RENDERING:
fgState.DirectContext = value;
break;
default:
fgWarning( "glutSetOption(): missing enum handle %i\n", eWhat );
break;
}
case GLUT_WINDOW_CURSOR:
if( fgStructure.Window != NULL )
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
: GLUT_CREATE_NEW_CONTEXT;
case GLUT_DIRECT_RENDERING:
return fgState.DirectContext;
break;
default:
fgWarning( "glutGet(): missing enum handle %i\n", eWhat );
break;

View File

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