cinder / Cinder

Cinder is a community-developed, free and open source library for professional-quality creative coding in C++.
http://libcinder.org
Other
5.28k stars 940 forks source link

Caching OpenGL values in static variables #1938

Open IntellectualKitty opened 6 years ago

IntellectualKitty commented 6 years ago

Static variables are used to cache values from OpenGL in functions such as GLint Fbo::getMaxSamples() and GLint Fbo::getMaxAttachments(). This doesn't seem to be particularly safe since it's possible that these values can change if the OpenGL context is recreated, especially on systems with multiple displays driven by different graphics cards.

GLint Fbo::getMaxSamples()
{
    static GLint sMaxSamples = -1;
#if ! defined( CINDER_GL_ES_2 )
    if( sMaxSamples < 0 ) {
        glGetIntegerv( GL_MAX_SAMPLES, &sMaxSamples);
    }

    return sMaxSamples;
#elif defined( CINDER_COCOA_TOUCH )
    if( sMaxSamples < 0 )
        glGetIntegerv( GL_MAX_SAMPLES_APPLE, &sMaxSamples);

    return sMaxSamples;
#else
    return 0;
#endif
}
richardeakin commented 6 years ago

Is there a case where you can operate an application with two videos cards that have different specs? AFAIK multi-gpu setups always require the same model card.

I do wonder however what happens when you dynamically switch between, say, your integrated and dedicated card while the app is running. Never tried myself, but I know you can manually force this (the system itself will pick one or the other right when the context is requested).