Skip to content

Commit dcf9aa1

Browse files
committed
Change GL context cvars to new-style
1 parent 0c0823a commit dcf9aa1

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/engine/renderer/tr_init.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3434

3535
static void GfxInfo_f();
3636

37-
cvar_t *r_glMajorVersion;
38-
cvar_t *r_glMinorVersion;
39-
cvar_t *r_glProfile;
4037
Cvar::Cvar<bool> r_glDebugProfile( "r_glDebugProfile", "Enable GL debug message callback", Cvar::NONE, false );
4138
Cvar::Range<Cvar::Cvar<int>> r_glDebugMode( "r_glDebugMode",
4239
"GL debug message callback mode: 0: none, 1: error, 2: deprecated, 3: undefined, 4: portability, 5: performance,"
4340
"6: other, 7: all", Cvar::NONE,
4441
Util::ordinal( glDebugModes_t::GLDEBUG_NONE ),
4542
Util::ordinal( glDebugModes_t::GLDEBUG_NONE ),
4643
Util::ordinal( glDebugModes_t::GLDEBUG_ALL ) );
47-
cvar_t *r_glAllowSoftware;
48-
cvar_t *r_glExtendedValidation;
44+
Cvar::Cvar<bool> r_glExtendedValidation( "r_glExtendedValidation",
45+
"Enable extra GL context validation", Cvar::NONE, false );
4946

5047
cvar_t *r_ignore;
5148

@@ -963,7 +960,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
963960
glConfig.vidWidth, glConfig.vidHeight,
964961
fsstrings[ +r_fullscreen.Get() ] );
965962

966-
if ( !!r_glExtendedValidation->integer )
963+
if ( r_glExtendedValidation.Get() )
967964
{
968965
Log::Notice("Using OpenGL version %d.%d, requested: %d.%d, highest: %d.%d",
969966
glConfig2.glMajor, glConfig2.glMinor, glConfig2.glRequestedMajor, glConfig2.glRequestedMinor,
@@ -1145,12 +1142,8 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
11451142
void R_Register()
11461143
{
11471144
// OpenGL context selection
1148-
r_glMajorVersion = Cvar_Get( "r_glMajorVersion", "", CVAR_LATCH );
1149-
r_glMinorVersion = Cvar_Get( "r_glMinorVersion", "", CVAR_LATCH );
1150-
r_glProfile = Cvar_Get( "r_glProfile", "", CVAR_LATCH );
11511145
Cvar::Latch( r_glDebugProfile );
1152-
r_glAllowSoftware = Cvar_Get( "r_glAllowSoftware", "0", CVAR_LATCH );
1153-
r_glExtendedValidation = Cvar_Get( "r_glExtendedValidation", "0", CVAR_LATCH );
1146+
Cvar::Latch( r_glExtendedValidation );
11541147

11551148
// latched and archived variables
11561149
r_picMip = Cvar_Get( "r_picMip", "0", CVAR_LATCH | CVAR_ARCHIVE );

src/engine/renderer/tr_local.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,16 +2918,10 @@ enum class shaderProfilerRenderSubGroupsMode {
29182918

29192919
extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init
29202920

2921-
//
29222921
// cvars
2923-
//
2924-
extern cvar_t *r_glMajorVersion; // override GL version autodetect (for testing)
2925-
extern cvar_t *r_glMinorVersion;
2926-
extern cvar_t *r_glProfile;
29272922
extern Cvar::Cvar<bool> r_glDebugProfile;
29282923
extern Cvar::Range<Cvar::Cvar<int>> r_glDebugMode;
2929-
extern cvar_t *r_glAllowSoftware;
2930-
extern cvar_t *r_glExtendedValidation;
2924+
extern Cvar::Cvar<bool> r_glExtendedValidation;
29312925

29322926
extern cvar_t *r_ignore; // used for debugging anything
29332927

src/engine/sys/sdl_glimp.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4141

4242
static Log::Logger logger("glconfig", "", Log::Level::NOTICE);
4343

44+
static Cvar::Range<Cvar::Cvar<int>> r_glMajorVersion( "r_glMajorVersion",
45+
"Force this GL major version; 0 to set up automatically", Cvar::NONE, 0, 0, 4 );
46+
static Cvar::Range<Cvar::Cvar<int>> r_glMinorVersion( "r_glMinorVersion",
47+
"Force this GL minor version; 0 to set up automatically", Cvar::NONE, 0, 0, 6 );
48+
static Cvar::Cvar<std::string> r_glProfile( "r_glProfile",
49+
"Force this GL profile (core or compat); empty to set up automatically", Cvar::NONE, "" );
50+
static Cvar::Cvar<bool> r_glAllowSoftware( "r_glAllowSoftware", "Allow software rendering", Cvar::NONE, false );
51+
4452
static Cvar::Modified<Cvar::Cvar<bool>> r_noBorder(
4553
"r_noBorder", "draw window without border", Cvar::ARCHIVE, false);
4654
static Cvar::Modified<Cvar::Range<Cvar::Cvar<int>>> r_swapInterval(
@@ -770,7 +778,8 @@ static void GLimp_SetAttributes( const glConfiguration &configuration )
770778
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0 );
771779
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
772780

773-
if ( !r_glAllowSoftware->integer )
781+
Cvar::Latch( r_glAllowSoftware );
782+
if ( !r_glAllowSoftware.Get() )
774783
{
775784
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
776785
}
@@ -1124,9 +1133,9 @@ static rserr_t GLimp_ValidateBestContext(
11241133
{ 1, 0, glProfile::COMPATIBILITY, true },
11251134
};
11261135

1127-
logger.Debug( "Validating best OpenGL context." );
1136+
logger.Debug( "Validating best OpenGL context" );
11281137

1129-
bool needHighestExtended = !!r_glExtendedValidation->integer;
1138+
bool needHighestExtended = r_glExtendedValidation.Get();
11301139
for ( int colorBits : {24, 16} )
11311140
{
11321141
for ( auto& row : glSupportArray )
@@ -1182,14 +1191,16 @@ static glConfiguration GLimp_ApplyCustomOptions( const int GLEWmajor, const glCo
11821191
{
11831192
glConfiguration customConfiguration = {};
11841193

1185-
if ( bestConfiguration.profile == glProfile::CORE && !Q_stricmp( r_glProfile->string, "compat" ) )
1194+
Cvar::Latch( r_glProfile );
1195+
const std::string glProfile = r_glProfile.Get();
1196+
if ( bestConfiguration.profile == glProfile::CORE && !Q_stricmp( glProfile.c_str(), "compat") )
11861197
{
11871198
logger.Debug( "Compatibility profile is forced by r_glProfile" );
11881199

11891200
customConfiguration.profile = glProfile::COMPATIBILITY;
11901201
}
11911202

1192-
if ( bestConfiguration.profile == glProfile::COMPATIBILITY && !Q_stricmp( r_glProfile->string, "core" ) )
1203+
if ( bestConfiguration.profile == glProfile::COMPATIBILITY && !Q_stricmp( glProfile.c_str(), "core" ) )
11931204
{
11941205
if ( GLEWmajor < 2 )
11951206
{
@@ -1204,8 +1215,10 @@ static glConfiguration GLimp_ApplyCustomOptions( const int GLEWmajor, const glCo
12041215
}
12051216
}
12061217

1207-
customConfiguration.major = std::max( 0, r_glMajorVersion->integer );
1208-
customConfiguration.minor = std::max( 0, r_glMinorVersion->integer );
1218+
Cvar::Latch( r_glMajorVersion );
1219+
Cvar::Latch( r_glMinorVersion );
1220+
customConfiguration.major = std::max( 0, r_glMajorVersion.Get() );
1221+
customConfiguration.minor = std::max( 0, r_glMinorVersion.Get() );
12091222

12101223
if ( customConfiguration.major == 0 )
12111224
{
@@ -1598,11 +1611,11 @@ static rserr_t GLimp_SetMode( const int mode, const bool fullscreen, const bool
15981611
static glConfiguration bestValidatedConfiguration = {}; // considering only up to OpenGL 3.2
15991612
static glConfiguration extendedValidationResult = {}; // max available OpenGL version for diagnostic purposes
16001613

1601-
if ( r_glExtendedValidation->integer && extendedValidationResult.major != 0 )
1614+
if ( r_glExtendedValidation.Get() && extendedValidationResult.major != 0 )
16021615
{
16031616
logger.Debug( "Previously best validated context: %s", ContextDescription( extendedValidationResult ) );
16041617
}
1605-
else if ( bestValidatedConfiguration.major == 0 || r_glExtendedValidation->integer )
1618+
else if ( bestValidatedConfiguration.major == 0 || r_glExtendedValidation.Get() )
16061619
{
16071620
// Detect best configuration.
16081621
rserr_t err = GLimp_ValidateBestContext( GLEWmajor, bestValidatedConfiguration, extendedValidationResult );
@@ -1621,7 +1634,7 @@ static rserr_t GLimp_SetMode( const int mode, const bool fullscreen, const bool
16211634
}
16221635
}
16231636

1624-
if ( r_glExtendedValidation->integer )
1637+
if ( r_glExtendedValidation.Get() )
16251638
{
16261639
logger.Notice( "Highest available context: %s", ContextDescription( extendedValidationResult ) );
16271640
}

0 commit comments

Comments
 (0)