MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / attachGLContextToRender

Method attachGLContextToRender

Engine/GPUContextPool.cpp:100–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100OSGLContextPtr
101GPUContextPool::attachGLContextToRender(bool checkIfGLLoaded)
102{
103 if (checkIfGLLoaded && (!appPTR->isOpenGLLoaded() || !appPTR->getCurrentSettings()->isOpenGLRenderingEnabled())) {
104 return OSGLContextPtr();
105 }
106 QMutexLocker k(&_imp->contextPoolMutex);
107
108 // Context-sharing disabled as it is not needed
109 OSGLContextPtr shareContext;// _imp->glShareContext.lock();
110 OSGLContextPtr newContext;
111 SettingsPtr settings = appPTR->getCurrentSettings();
112 GLRendererID rendererID;
113 if (settings) {
114 rendererID = settings->getActiveOpenGLRendererID();
115 }
116
117 int maxContexts = settings ? std::max(settings->getMaxOpenGLContexts(), 1) : 1;
118
119#ifndef NATRON_RENDER_SHARED_CONTEXT
120 while (_imp->glContextPool.empty() && (int)_imp->attachedGLContexts.size() >= maxContexts) {
121 _imp->glContextPoolEmpty.wait(k.mutex());
122 }
123 if ( _imp->glContextPool.empty() ) {
124 assert( (int)_imp->attachedGLContexts.size() < maxContexts );
125 // Create a new one
126 newContext = std::make_shared<OSGLContext>( FramebufferConfig(), shareContext.get(), GLVersion.major, GLVersion.minor, rendererID );
127 } else {
128 std::set<OSGLContextPtr>::iterator it = _imp->glContextPool.begin();
129 newContext = *it;
130 assert(newContext);
131 _imp->glContextPool.erase(it);
132 }
133#else
134
135 if ( (int)_imp->glContextPool.size() < maxContexts ) {
136 // Create a new one
137 newContext = std::make_shared<OSGLContext>( FramebufferConfig(), shareContext.get(), GLVersion.major, GLVersion.minor, rendererID );
138 _imp->glContextPool.insert(newContext);
139 } else {
140 while ((int)_imp->glContextPool.size() > maxContexts) {
141 _imp->glContextPool.erase(_imp->glContextPool.begin());
142 }
143
144 // Cycle through all contexts for all renders
145 OSGLContextPtr lastContext = _imp->lastUsedGLContext.lock();
146 if (!lastContext) {
147 newContext = *_imp->glContextPool.begin();
148 } else {
149 std::set<OSGLContextPtr>::iterator foundLast = _imp->glContextPool.find(lastContext);
150 assert( foundLast != _imp->glContextPool.end() );
151 if ( foundLast == _imp->glContextPool.end() ) {
152 throw std::logic_error("No context to attach");
153 } else {
154 std::set<OSGLContextPtr>::iterator next = foundLast;
155 ++next;
156 if ( next == _imp->glContextPool.end() ) {
157 next = _imp->glContextPool.begin();

Callers 2

Calls 15

maxFunction · 0.85
FramebufferConfigClass · 0.85
isOpenGLLoadedMethod · 0.80
getCurrentSettingsMethod · 0.80
getMaxOpenGLContextsMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected