OpenGLContextLock StimulusDisplay::setCurrent(int i){ if ((i >= getNContexts()) || (i < 0)) { merror(M_DISPLAY_MESSAGE_DOMAIN, "invalid context index (%d)", i); return OpenGLContextLock(); } return opengl_context_manager->setCurrent(context_ids[i]); }
void StimulusDisplay::refreshDisplay() { // // Determine whether we need to draw // const bool updateIsExplicit = needDraw; if (!needDraw) { shared_ptr<StimulusNode> node = display_stack->getFrontmost(); while (node) { if (node->isVisible()) { needDraw = node->needDraw(); if (needDraw) break; } node = node->getNext(); } } if (!(needDraw || drawEveryFrame)) { return; } // // Draw stimuli // for (int i = 0; i < getNContexts(); i++) { OpenGLContextLock ctxLock = setCurrent(i); current_context_index = i; if (!needDraw) { if (drawEveryFrame) { drawStoredBuffer(i); } } else { drawDisplayStack(i == 0); if (drawEveryFrame) { storeBackBuffer(i); } } if (i != 0) { // Non-main display opengl_context_manager->updateAndFlush(i); } else { // Main display opengl_context_manager->flush(i); if (needDraw) { announceDisplayUpdate(updateIsExplicit); } } } current_context_index = -1; needDraw = false; }
void StimulusDisplay::addContext(int _context_id){ context_ids.push_back(_context_id); int contextIndex = getNContexts() - 1; if (0 == contextIndex) { if (kCVReturnSuccess != opengl_context_manager->prepareDisplayLinkForMainDisplay(displayLink)) { throw SimpleException("Unable to associate display link with main display"); } setMainDisplayRefreshRate(); } if (drawEveryFrame) { OpenGLContextLock ctxLock = setCurrent(contextIndex); allocateBufferStorage(contextIndex); } }