Exemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
/// Constructor
///
/// Tries to create a widget that shares OpenGL resources with \a shareWidget
/// To check if creation was actually successful, you must call isValidContext() on the context
/// of the newly created widget. For example:
/// \code
/// myNewWidget->cvfOpenGLContext()->isValidContext();
/// \endcode
///
/// If the context is not valid, sharing failed and the newly created widget/context be discarded.
//--------------------------------------------------------------------------------------------------
OpenGLWidget::OpenGLWidget(OpenGLWidget* shareWidget, QWidget* parent , Qt::WindowFlags f)
:   QGLWidget(new cvfqt::CvfBoundQGLContext(shareWidget->cvfOpenGLContext()->group(), shareWidget->format()), parent, shareWidget, f)
{
    CVF_ASSERT(shareWidget);
    cvf::ref<cvf::OpenGLContext> shareContext = shareWidget->cvfOpenGLContext();
    CVF_ASSERT(shareContext.notNull());

    cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
    if (myContext.notNull())
    {
        // We need to check if we actually got a context that shares resources with shareWidget.
        if (isSharing())
        {
            if (isValid())
            {
                CVF_ASSERT(myContext->group() == shareContext->group());
                myContext->initializeContext();
            }
        }
        else
        {
            // If we didn't, we need to remove the newly created context from the group it has been added to since
            // the construction process above has already optimistically added the new context to the existing group.
            // In this case, the newly context is basically defunct so we just shut it down (which will also remove it from the group)
            myContext->shutdownContext();
            CVF_ASSERT(myContext->group() == NULL);
        }
    }
}
Exemplo n.º 2
0
void GLBox::initializeGL()
{
    // Let OpenGL clear to black
    qglClearColor( black ); 

    glEnable(GL_DEPTH_TEST);

    if ( sharedListUsers == 0 ) {	// No shared list has been made yet
	sharedDisplayList = makeObject();	// Make one
	object = sharedDisplayList;		// Use it
	sharedListUsers++;				// Keep reference count
	qDebug( "GLBox %s created shared display list.", name() );
    }
    else {				// There is a shared diplay list
	if ( isSharing() ) {		// Can we access it?
	    object = sharedDisplayList;		// Yes, use it
	    sharedListUsers++;			// Keep reference count
	    qDebug( "GLBox %s uses shared display list.", name() );
	}
	else {				
	    localDisplayList = makeObject();	// No, roll our own
	    object = localDisplayList;		// and use that
	    qDebug( "GLBox %s uses private display list.", name() );
	}
    }
}
Exemplo n.º 3
0
GLWindow::GLWindow(const QRectF& normalizedCoordinates, const QRect& windowRect, QGLWidget* shareWidget)
  : QGLWidget(0, shareWidget)
  , backgroundColor_(Qt::black)
  , normalizedCoordinates_(normalizedCoordinates)
{
    setGeometry(windowRect);
    setCursor(Qt::BlankCursor);

    if(shareWidget && !isSharing())
        throw std::runtime_error("failed to share OpenGL context");

    setAutoBufferSwap(false);
}
Exemplo n.º 4
0
GLWindow::GLWindow(int tileIndex, QRect windowRect, QGLWidget * shareWidget) : QGLWidget(0, shareWidget)
{
    tileIndex_ = tileIndex;
    setGeometry(windowRect);

    // make sure sharing succeeded
    if(shareWidget != 0 && isSharing() != true)
    {
        put_flog(LOG_FATAL, "failed to share OpenGL context");
        exit(-1);
    }

    // disable automatic buffer swapping
    setAutoBufferSwap(false);
}
Exemplo n.º 5
0
bool QGLWidget::event(QEvent *e)
{
    Q_D(QGLWidget);
    if (e->type() == QEvent::ParentChange) {
        setContext(new QGLContext(d->glcx->requestedFormat(), this));
        // the overlay needs to be recreated as well
        delete d->olcx;
        if (isValid() && context()->format().hasOverlay()) {
            d->olcx = new QGLContext(QGLFormat::defaultOverlayFormat(), this);
            if (!d->olcx->create(isSharing() ? d->glcx : 0)) {
                delete d->olcx;
                d->olcx = 0;
                d->glcx->d_func()->glFormat.setOverlay(false);
            }
        } else {
            d->olcx = 0;
        }
    } else if (e->type() == QEvent::Show && !format().rgba()) {
        d->updateColormap();
    }

    return QWidget::event(e);
}
void SimObjectWidget::initializeGL()
{
  objectRenderer.init(isSharing());
}
Exemplo n.º 7
0
 void initializeGL()
 {
   objectRenderer.init(isSharing());
 }
Exemplo n.º 8
0
void solver::solve(){
	// build constraints
	badHoles = 0;
	emptyHoles = 0;
	bool trivialHoles = false;
	cons8V.clear();
	//safe.clear();
	//bomb.clear();
	for(int i=0; i<40; ++i){
		if(cellColors[i] > 5)
			badHoles++;
		else if(cellColors[i] == 0)
			emptyHoles++;
		else{
			constraint_t cons8;
			cons8.base = i;
			cons8.spacesLeft = 0;
			cons8.minesLeft = 2*(cellColors[i]-1);
			if(i%8 == 0){
				if(i>=8){
					modConstraint(&cons8, i-8);
					modConstraint(&cons8, i-7);
				}
				modConstraint(&cons8, i+1);
				if(i<32){
					modConstraint(&cons8, i+8);
					modConstraint(&cons8, i+9);
				}
			}else if(i%8 == 7){
				if(i>=8){
					modConstraint(&cons8, i-9);
					modConstraint(&cons8, i-8);
				}
				modConstraint(&cons8, i-1);
				if(i<32){
					modConstraint(&cons8, i+7);
					modConstraint(&cons8, i+8);
				}
			}else{
				if(i>=8){
					modConstraint(&cons8, i-9);
					modConstraint(&cons8, i-8);
					modConstraint(&cons8, i-7);
				}
				modConstraint(&cons8, i-1);
				modConstraint(&cons8, i+1);
				if(i<32){
					modConstraint(&cons8, i+7);
					modConstraint(&cons8, i+8);
					modConstraint(&cons8, i+9);
				}
			}
			// test for empty constraint
			if(cons8.spacesLeft != 0){
				cons8V.push_back(cons8);
				/*if(cons8.minesLeft == 0){
					trivialHoles = true;
					for(int j=0; j<cons8.spacesLeft; ++j)
						safe.push_back(cons8.spaces[j]);
				}else if(cons8.spacesLeft >= cons8.minesLeft){
					cons8V.push_back(cons8);
				}else{
					trivialHoles = true;
					for(int j=0; j<cons8.spacesLeft; ++j)
						bomb.push_back(cons8.spaces[j]);
				}*/
			}
		}
	}
	//unsigned char basePercent = (unsigned char)((100.0*(16-badHoles))/emptyHoles);
	for(int i=0; i<40; i++){
		percents[i] = -1;
	}
	//if(trivialHoles)
		//return;

	//simplify constraints
	/*for(int i=0; i<cons8V.size(); ++i){
		for(int j=0; j<cons8V.size(); ++j){
			if(i==j)
				continue;
			if(isSubset(i,j)){
				constraint_t cons8i = cons8V.at(i);
				constraint_t cons8j = cons8V.at(j);
				int l=0;
				int m=0;
				for(int k=0; k < cons8i.spacesLeft; ++k, ++l){
					while(cons8j.spaces[l] != cons8i.spaces[k]){
						cons8j.spaces[m++] = cons8j.spaces[l++];
					}
				}
				cons8j.spacesLeft -= cons8i.spacesLeft;
				if(cons8j.spacesLeft != 0){
				if(cons8.minesLeft == 0){
			}
		}
	}*/
	avgMines = 0.0;
	for(int i=0; i<40; ++i){
		cons8Done[i] = false;
		spaceBad[i] = 0;
	}
	for(int i=0; i<17; ++i)
		for(int j=0; j<46; ++j)
			solutions[i][j] = 0;
	int subsetIndex = 0;
	for(unsigned int i=0; i<cons8V.size(); ++i){
		if(cons8Done[i])
			continue;
		// build coupled subset of constraints
		cons8cupV.clear();
		cons8spacesV.clear();
		addConstraintToCup(i);
		for(unsigned int j=0; j<cons8cupV.size(); ++j){
			for(unsigned int k=0; k<cons8V.size(); ++k){
				if(cons8Done[k])
					continue;
				if(isSharing(j,k)){
					addConstraintToCup(k);
				}
			}
		}
		// find all possible solutions to subset
		coupledSubsetSolver(0, subsetIndex);
		for(unsigned char j=0; j<cons8spacesV.size(); ++j){
			spacesForSubset[subsetIndex][j] = cons8spacesV.at(j);
		}
		spacesForSubset[subsetIndex][39] = cons8spacesV.size();
		subsetIndex++;
	}
	// remove invalid solution sets
	int minMines = badHoles;
	for(int i=0; i<subsetIndex; ++i){
		int lowestSolution = 0;
		for(int j=0; j<17; ++j){
			if(solutions[j][40+i] != 0){
				lowestSolution = j;
				break;
			}
		}
		minMines += lowestSolution;
	}
	for(int i=0; i<subsetIndex; ++i){
		int lowestSolution = 0;
		for(int j=0; j<17; ++j){
			if(solutions[j][40+i] != 0){
				lowestSolution = j;
				break;
			}
		}
		for(int j=16; j>0; --j){
			if(solutions[j][40+i] != 0){
				if(minMines-lowestSolution+j > 16){
					int badToRemove = minMines-lowestSolution+j-16;
					for(int k=j; k>j-badToRemove; --k){
						solutions[k][40+i] = 0;
					}
				}
				break;
			}
		}
	}
	// calculate percents
	for(int i=0; i<subsetIndex; ++i){
		int totalSln = 0;
		int weightedMines = 0;
		for(int k=0; k<17; ++k){
			if(solutions[k][40+i] == 0)
				continue;
			totalSln += solutions[k][40+i];
			weightedMines += k*solutions[k][40+i];
		}
		avgMines += ((double)weightedMines)/totalSln;
		for(unsigned char j=0; j<spacesForSubset[i][39]; ++j){
			unsigned char space = spacesForSubset[i][j];
			int spaceSln = 0;
			for(int k=0; k<17; ++k)
				if(solutions[k][40+i] != 0)
					spaceSln += solutions[k][space];
			percents[space] = (unsigned char)((100.0*spaceSln)/totalSln);
		}
	}

	emptyHoles = 0;
	for(int i=0; i<40; i++){
		if(percents[i] == -1 && cellColors[i] == 0)
			emptyHoles++;
	}
	unsigned char basePercent = (unsigned char)((100.0*(16-badHoles-avgMines))/emptyHoles);
	for(int i=0; i<40; i++){
		if(percents[i] == -1 && cellColors[i] == 0)
			percents[i] = basePercent;
	}
}