예제 #1
0
void StimulusDisplay::addContext(int _context_id){
	context_ids.push_back(_context_id);
    int contextIndex = context_ids.size() - 1;
    
    OpenGLContextLock ctxLock = opengl_context_manager->setCurrent(_context_id);
    getCurrentViewportSize(bufferWidths[contextIndex], bufferHeights[contextIndex]);
    
    CVDisplayLinkRef dl;
    
    if (kCVReturnSuccess != CVDisplayLinkCreateWithActiveCGDisplays(&dl)) {
        throw SimpleException("Unable to create display link");
    }
    
    displayLinks.push_back(dl);
    displayLinkContexts.emplace_back(new DisplayLinkContext(this, contextIndex));
    
    if (kCVReturnSuccess != CVDisplayLinkSetOutputCallback(dl,
                                                           &StimulusDisplay::displayLinkCallback,
                                                           displayLinkContexts.back().get()))
    {
        throw SimpleException("Unable to set display link output callback");
    }
    
    if (kCVReturnSuccess != opengl_context_manager->prepareDisplayLinkForContext(dl, _context_id)) {
        throw SimpleException("Unable to associate display link with OpenGL context");
    }
    
    if (0 == contextIndex) {
        setMainDisplayRefreshRate();
        allocateBufferStorage();
    }
}
예제 #2
0
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);
    }
}