Esempio n. 1
0
QPixmap QGLWidget::renderPixmap( int w, int h, bool useContext )
{
    QPixmap nullPm;
    QSize sz = size();
    if ( (w > 0) && (h > 0) )
	sz = QSize( w, h );
    QPixmap pm( sz );
    glcx->doneCurrent();
    bool success = TRUE;

    if ( useContext && isValid() && renderCxPm( &pm ) )
	return pm;

    QGLFormat fmt = format();
    fmt.setDirectRendering( FALSE );		// No direct rendering
    fmt.setDoubleBuffer( FALSE );		// We don't need dbl buf
    QGLContext* pcx = new QGLContext( fmt, &pm );
    QGLContext* ocx = (QGLContext*)context();
    setContext( pcx, 0, FALSE );
    if ( pcx->isValid() )
	updateGL();
    else
	success = FALSE;
    setContext( ocx );				// Will delete pcx

    if ( success )
	return pm;
    else
	return nullPm;
}
static PyObject *meth_QGLContext_create(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds)
{
    PyObject *sipParseErr = NULL;
    bool sipSelfWasArg = (!sipSelf || sipIsDerived((sipSimpleWrapper *)sipSelf));

    {
        const QGLContext* a0 = 0;
        QGLContext *sipCpp;

        static const char *sipKwdList[] = {
            sipName_shareContext,
        };

        if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "B|J8", &sipSelf, sipType_QGLContext, &sipCpp, sipType_QGLContext, &a0))
        {
            bool sipRes;

            sipRes = (sipSelfWasArg ? sipCpp->QGLContext::create(a0) : sipCpp->create(a0));

            return PyBool_FromLong(sipRes);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QGLContext, sipName_create, doc_QGLContext_create);

    return NULL;
}
void StelQGLTextureBackend::loadFromPVR()
{
	invariant();
	//NOTE: We ignore bind options (mipmapping and filtering type) from params
	//      at the moment.
	//
	//      We also ignore maximum texture size (QGLContext::bindTexture should 
	//      fail if the texture is too large.
	//
	//      QGLContext::bindTexture handles gl texture format for us.
	QGLContext* context = prepareContextForLoading();
	glTextureID = context->bindTexture(path);
	if(glTextureID == 0)
	{
		errorOccured("loadFromPVR() failed to load a PVR file to a GL texture - "
		             "Maybe the file \"" + path + "\" is missing?");
		invariant();
		return;
	}
	// For some reason only LINEAR seems to work.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	setTextureWrapping();

	// This is an assumption; PVRTC can be either 4 or 2 bits per pixel - we assume the worse case.
	pixelBytes = 0.5f;

	completeLoading();
	invariant();
}
Esempio n. 4
0
bool Texture::load( const QUrl& url )
{
#ifdef __GNUC__
#warning Todo: Add support for non-2D textures and non-RGBA colour formats. Also, find a way \
around the nasty const_cast .
#endif

    if( d->glTexture )
        return true;

    if( !QGLContext::currentContext() || !QGLContext::currentContext()->isValid() )
        return false;

    QImage image;
    image.load( url.toLocalFile() );

    QGLContext* context = const_cast<QGLContext*>( QGLContext::currentContext() );
    d->glTexture = context->bindTexture( image );

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
#ifndef GLUON_GRAPHICS_GLES
    glTexParameterf( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE );
#endif

    if( d->glTexture != 0 )
        return true;

    return false;
}
Esempio n. 5
0
bool QX11GLWindowSurface::scroll(const QRegion &area, int dx, int dy)
{
    if (m_backBuffer.isNull())
        return false;

    Q_ASSERT(m_backBuffer.data_ptr()->classId() == QPixmapData::X11Class);

    // Make sure all GL rendering is complete before starting the scroll operation:
    QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.data_ptr().data())->context();
    if (QGLContext::currentContext() != ctx && ctx && ctx->isValid())
        ctx->makeCurrent();
    eglWaitClient();

    if (!m_pixmapGC)
        m_pixmapGC = XCreateGC(X11->display, m_backBuffer.handle(), 0, 0);

    foreach (const QRect& rect, area.rects()) {
        XCopyArea(X11->display, m_backBuffer.handle(), m_backBuffer.handle(), m_pixmapGC,
                  rect.x(), rect.y(), rect.width(), rect.height(),
                  rect.x()+dx, rect.y()+dy);
    }

    // Make sure the scroll operation is complete before allowing GL rendering to resume
    eglWaitNative(EGL_CORE_NATIVE_ENGINE);

    return true;
}
Esempio n. 6
0
void QGLPaintDevice::beginPaint()
{
    // Make sure our context is the current one:
    QGLContext *ctx = context();
    ctx->makeCurrent();

    // Record the currently bound FBO so we can restore it again
    // in endPaint() and bind this device's FBO
    //
    // Note: m_thisFBO could be zero if the paint device is not
    // backed by an FBO (e.g. window back buffer).  But there could
    // be a previous FBO bound to the context which we need to
    // explicitly unbind.  Otherwise the painting will go into
    // the previous FBO instead of to the window.
    m_previousFBO = ctx->d_func()->current_fbo;

    if (m_previousFBO != m_thisFBO) {
        ctx->d_ptr->current_fbo = m_thisFBO;
        glBindFramebuffer(GL_FRAMEBUFFER, m_thisFBO);
    }

    // Set the default fbo for the context to m_thisFBO so that
    // if some raw GL code between beginNativePainting() and
    // endNativePainting() calls QGLFramebufferObject::release(),
    // painting will revert to the window surface's fbo.
    ctx->d_ptr->default_fbo = m_thisFBO;
}
HostWindowDataOpenGL::~HostWindowDataOpenGL()
{
	QGLContext* gc = (QGLContext*) QGLContext::currentContext();
	if (gc) {
		if (m_textureId)
			gc->deleteTexture(m_textureId);
	}
}
void MGLES2RendererPrivate::init()
{
    m_initialized = true;

    //init world matrix for the known parts
    //parts that are changeable by the transformation
    //are set when rendering in the textures
    m_matWorld[0][2] = 0.0;
    m_matWorld[1][2] = 0.0;
    m_matWorld[2][0] = 0.0;
    m_matWorld[2][1] = 0.0;
    m_matWorld[2][2] = 1.0;
    m_matWorld[2][3] = 0.0;
    m_matWorld[3][2] = 0.0;

    //init vertex and texcoord arrays, 4 first vertices are used to draw standard
    //pixmaps and all the remaining vertices can be used to draw dynamic geometries
    //like scalable images and other patched stuff, the vertices are packed into same
    //array so that we don't need to switch the used array on fly.
    m_vertices.resize(8 + (9 * 4 * 2));
    m_texCoords.resize(8 + (9 * 4 * 2));
    GLfloat *tc = m_texCoords.data();
    tc[0] = 0.0; tc[1] = 1.0;
    tc[2] = 0.0; tc[3] = 0.0;
    tc[4] = 1.0; tc[5] = 0.0;
    tc[6] = 1.0; tc[7] = 1.0;

    //init index array that is used to draw dynamic geometries
    //the indices are offset by 4 because the 4 vertices that
    //are used to draw normal pixmaps are in the beginning of
    //the array
    m_indices.resize(9 * 6);
    GLushort *indices = m_indices.data();
    for (GLuint i = 0; i < 9; i++) {
        indices[i*6+0] = 4 + (i * 4 + 0); //x1 y1 TL
        indices[i*6+1] = 4 + (i * 4 + 1); //x1 y2 BL
        indices[i*6+2] = 4 + (i * 4 + 2); //x2 y2 BR
        indices[i*6+3] = 4 + (i * 4 + 0); //x1 y1 TL
        indices[i*6+4] = 4 + (i * 4 + 2); //x2 y2 BR
        indices[i*6+5] = 4 + (i * 4 + 3); //x2 y1 TR
    }

    m_glContext->makeCurrent();

    //init the orthogonal projection matrix
    //glOrtho(0, w, h, 0, -1, 1):
    //2.0/w,  0.0,    0.0, -1.0
    //0.0,   -2.0/h,  0.0,  1.0
    //0.0,    0.0,   -1.0,  0.0
    //0.0,    0.0,    0.0,  1.0
    GLfloat w = m_glContext->device()->width();
    GLfloat h = m_glContext->device()->height();
    m_matProj[0][0] =  2.0f / w; m_matProj[1][0] =  0.0;   m_matProj[2][0] =  0.0; m_matProj[3][0] = -1.0;
    m_matProj[0][1] =  0.0;   m_matProj[1][1] = -2.0f / h; m_matProj[2][1] =  0.0; m_matProj[3][1] =  1.0;
    m_matProj[0][2] =  0.0;   m_matProj[1][2] =  0.0;   m_matProj[2][2] = -1.0; m_matProj[3][2] =  0.0;
    m_matProj[0][3] =  0.0;   m_matProj[1][3] =  0.0;   m_matProj[2][3] =  0.0; m_matProj[3][3] =  1.0;
}
Esempio n. 9
0
void CTexture::loadFromFile(const char *fileName)
{
    QGLContext *context = const_cast<QGLContext*>(QGLContext::currentContext());
    QImage img;
    img.load(fileName);
    id=context->bindTexture(img);

    width = img.width();
    height = img.height();
}
Esempio n. 10
0
void QGLPaintDevice::endPaint()
{
    // Make sure the FBO bound at beginPaint is re-bound again here:
    QGLContext *ctx = context();
    if (m_previousFBO != ctx->d_func()->current_fbo) {
        ctx->d_ptr->current_fbo = m_previousFBO;
        glBindFramebuffer(GL_FRAMEBUFFER, m_previousFBO);
    }

    ctx->d_ptr->default_fbo = 0;
}
Esempio n. 11
0
/*! \fn QGLPixelBuffer::~QGLPixelBuffer()

    Destroys the pbuffer and frees any allocated resources.
*/
QGLPixelBuffer::~QGLPixelBuffer()
{
    Q_D(QGLPixelBuffer);

    // defined in qpaintengine_opengl.cpp
    QGLContext *current = const_cast<QGLContext *>(QGLContext::currentContext());
    if (current != d->qctx)
        makeCurrent();
    d->cleanup();
    if (current && current != d->qctx)
        current->makeCurrent();
}
Esempio n. 12
0
static PyObject *meth_QGLContext_drawTexture(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds)
{
    PyObject *sipParseErr = NULL;

    {
        const QRectF* a0;
        GLuint a1;
        GLenum a2 = GL_TEXTURE_2D;
        QGLContext *sipCpp;

        static const char *sipKwdList[] = {
            NULL,
            NULL,
            sipName_textureTarget,
        };

        if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "BJ9u|u", &sipSelf, sipType_QGLContext, &sipCpp, sipType_QRectF, &a0, &a1, &a2))
        {
            sipCpp->drawTexture(*a0,a1,a2);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    {
        const QPointF* a0;
        int a0State = 0;
        GLuint a1;
        GLenum a2 = GL_TEXTURE_2D;
        QGLContext *sipCpp;

        static const char *sipKwdList[] = {
            NULL,
            NULL,
            sipName_textureTarget,
        };

        if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "BJ1u|u", &sipSelf, sipType_QGLContext, &sipCpp, sipType_QPointF, &a0, &a0State, &a1, &a2))
        {
            sipCpp->drawTexture(*a0,a1,a2);
            sipReleaseType(const_cast<QPointF *>(a0),sipType_QPointF,a0State);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QGLContext, sipName_drawTexture, doc_QGLContext_drawTexture);

    return NULL;
}
Esempio n. 13
0
void QGLPaintDevice::ensureActiveTarget()
{
    QGLContext* ctx = context();
    if (ctx != QGLContext::currentContext())
        ctx->makeCurrent();

    if (ctx->d_ptr->current_fbo != m_thisFBO) {
        ctx->d_ptr->current_fbo = m_thisFBO;
        glBindFramebuffer(GL_FRAMEBUFFER, m_thisFBO);
    }

    ctx->d_ptr->default_fbo = m_thisFBO;
}
Esempio n. 14
0
void QGLPaintDevice::endPaint()
{
    // Make sure the FBO bound at beginPaint is re-bound again here:
    QGLContext *ctx = context();

    ctx->d_func()->refreshCurrentFbo();

    if (m_previousFBO != ctx->d_func()->current_fbo) {
        ctx->d_func()->setCurrentFbo(m_previousFBO);
        ctx->contextHandle()->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_previousFBO);
    }

    ctx->d_ptr->default_fbo = 0;
}
//Image struct is copied (data is not - implicit sharing), so that
//ensureTextureSizeWithinLimits won't affect the original image.
void StelQGLTextureBackend::loadFromImage(QImage image)
{
	invariant();

	if(image.isNull())
	{
		errorOccured("loadFromImage(): Image data to load from is null. "
		             "Maybe the image failed to load from file?");
		invariant();
		return;
	}

	// Shrink if needed.
	glEnsureTextureSizeWithinLimits(image);

	if(!renderer->areNonPowerOfTwoTexturesSupported() && 
		(!StelUtils::isPowerOfTwo(image.width()) ||
		 !StelUtils::isPowerOfTwo(image.height())))
	{
		errorOccured("loadFromImage(): Failed to load because the image has "
		             "non-power-of-two width and/or height while the renderer "
		             "backend only supports power-of-two dimensions");
		invariant();
		return;
	}

	GLint internalFormat = glGetTextureInternalFormat(image);
	switch(internalFormat)
	{
		case GL_RGBA8:             pixelBytes = 4.0f; break;
		case GL_RGB8:              pixelBytes = 3.0f; break;
		case GL_LUMINANCE8_ALPHA8: pixelBytes = 2.0f; break;
		case GL_LUMINANCE8:        pixelBytes = 1.0f; break;
		default: Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown GL internal format for QImage");
	}

	QGLContext* context = prepareContextForLoading();
	glTextureID = context->bindTexture(image, GL_TEXTURE_2D, internalFormat,
	                                   getTextureBindOptions(textureParams));
	if(glTextureID == 0)
	{
		errorOccured("loadFromImage(): Failed to load an image to a GL texture");
		invariant();
		return;
	}
	setTextureWrapping();

	completeLoading();                       
	invariant();
}
void HostWindowDataOpenGL::initializePixmap(QPixmap& screenPixmap)
{
	QGLContext* gc = (QGLContext*) QGLContext::currentContext();
	if (gc) {
		if (m_textureId)
			gc->deleteTexture(m_textureId);

		screenPixmap = QPixmap(m_width, m_height);
        screenPixmap.fill(QColor(255,255,255,0));
		m_textureId = gc->bindTexture(screenPixmap, GL_TEXTURE_2D, kGLInternalFormat,
									  QGLContext::PremultipliedAlphaBindOption);
	}
	m_dirty = true;
}
Esempio n. 17
0
void QGLPaintDevice::ensureActiveTarget()
{
    QGLContext* ctx = context();
    if (ctx != QGLContext::currentContext())
        ctx->makeCurrent();

    ctx->d_func()->refreshCurrentFbo();

    if (ctx->d_ptr->current_fbo != m_thisFBO) {
        ctx->d_func()->setCurrentFbo(m_thisFBO);
        ctx->contextHandle()->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_thisFBO);
    }

    ctx->d_ptr->default_fbo = m_thisFBO;
}
Esempio n. 18
0
void SN_CheckerGL::doInit() {

	if (!scene()) {
		qCritical() << "SN_CheckerGL::doInit() : I'm not added to the scene yet";
	}

	QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext());
	if (!ctx || ctx->device()->paintEngine()->type() != QPaintEngine::OpenGL2 ) {
		qCritical() << "\n\n !! SN_CheckerGL::doInit() : no OpenGL context !!";
	}

	//
	// init opengl related stuff
	//
	glGenTextures(1, &_textureid);

	glDisable(GL_TEXTURE_2D);
	glEnable(GL_TEXTURE_RECTANGLE_ARB);

	glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _textureid);

	glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	// internal format 2 -> the number of color components in the texture
	glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, _pixelFormat, _imgsize.width(), _imgsize.height(), 0, _pixelFormat, GL_UNSIGNED_BYTE, (void *)0 /*static_cast<QImage *>(doubleBuffer->getFrontBuffer())->bits()*/);

	glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
	glDisable(GL_TEXTURE_RECTANGLE_ARB);
	glEnable(GL_TEXTURE_2D);

	//
	// init worker
	//
	_workerThread->setBufPtr(_image->bits()); // now worker is ready to work

	// run the thread
	_workerThread->start();

	// writeData() will call itself continuously (as long as the eventloop of the thread is running)
//	if ( ! QMetaObject::invokeMethod(_workerThread, "writeData", Qt::QueuedConnection) ) {
//		qDebug() << "SN_CheckerGL::doInit() : Failed to invoke Worker::writeData()";
//	}

	scheduleUpdate();
}
Esempio n. 19
0
void CWater::initializeGL()
{
    noise.gen(time(NULL));

    water_shader.addShaderFromSourceFile(QGLShader::Vertex,":/shaders/water.vert");
    water_shader.addShaderFromSourceFile(QGLShader::Fragment,":/shaders/water.frag");
    water_shader.link();
    water_shader.bind();
    water_shader.setUniformValue("sky_map",0);
    water_shader.setUniformValue("noise_table",1);
    water_shader.release();

    QImage img("tex/sky.jpg");
    QGLContext *context = const_cast<QGLContext*>(QGLContext::currentContext());
    sky_tex=context->bindTexture(img);
}
Esempio n. 20
0
void QGLWidget::setContext(QGLContext *context,
                            const QGLContext* shareContext,
                            bool deleteOldContext)
{
    Q_D(QGLWidget);
    if (context == 0) {
        qWarning("QGLWidget::setContext: Cannot set null context");
        return;
    }
    if (!context->deviceIsPixmap() && context->device() != this) {
        qWarning("QGLWidget::setContext: Context must refer to this widget");
        return;
    }

    if (d->glcx)
        d->glcx->doneCurrent();
    QGLContext* oldcx = d->glcx;
    d->glcx = context;

    bool doShow = false;
    if (oldcx && oldcx->d_func()->win == winId() && !d->glcx->deviceIsPixmap()) {
        // We already have a context and must therefore create a new
        // window since Windows does not permit setting a new OpenGL
        // context for a window that already has one set.
        doShow = isVisible();
        QWidget *pW = static_cast<QWidget *>(parent());
        QPoint pos = geometry().topLeft();
        setParent(pW, windowFlags());
        move(pos);
    }

    if (!d->glcx->isValid()) {
        d->glcx->create(shareContext ? shareContext : oldcx);
        // the above is a trick to keep disp lists etc when a
        // QGLWidget has been reparented, so remove the sharing
        // flag if we don't actually have a sharing context.
        if (!shareContext)
            d->glcx->d_ptr->sharing = false;
    }

    if (deleteOldContext)
        delete oldcx;

    if (doShow)
        show();
}
Esempio n. 21
0
void CButton::loadTextures(const char *normalTex, const char *selectedTex, const char *pressedTex)
{
    QGLContext *context = const_cast<QGLContext*>(QGLContext::currentContext());

    QImage img;

    img.load(normalTex);
    normalId=context->bindTexture(img);

    img.load(selectedTex);
    selectedId=context->bindTexture(img);

    img.load(pressedTex);
    pressedId=context->bindTexture(img);

    setWindowSize( img.width(), img.height() );
}
Esempio n. 22
0
void QX11GLWindowSurface::flush(QWidget *widget, const QRegion &widgetRegion, const QPoint &offset)
{
    // We don't need to know the widget which initiated the flush. Instead we just use the offset
    // to translate the widgetRegion:
    Q_UNUSED(widget);

    if (m_backBuffer.isNull()) {
        qDebug("QX11GLWindowSurface::flush() - backBuffer is null, not flushing anything");
        return;
    }

    Q_ASSERT(window()->size() != m_backBuffer.size());

    // Wait for all GL rendering to the back buffer pixmap to complete before trying to
    // copy it to the window. We do this by making sure the pixmap's context is current
    // and then call eglWaitClient. The EGL 1.4 spec says eglWaitClient doesn't have to
    // block, just that "All rendering calls...are guaranteed to be executed before native
    // rendering calls". This makes it potentially less expensive than glFinish.
    QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.data_ptr().data())->context();
    if (QGLContext::currentContext() != ctx && ctx && ctx->isValid())
        ctx->makeCurrent();
    eglWaitClient();

    if (m_windowGC == 0) {
        XGCValues attribs;
        attribs.graphics_exposures = False;
        m_windowGC = XCreateGC(X11->display, m_window->handle(), GCGraphicsExposures, &attribs);
    }

    int rectCount;
    XRectangle *rects = (XRectangle *)qt_getClipRects(widgetRegion, rectCount);
    if (rectCount <= 0)
        return;

    XSetClipRectangles(X11->display, m_windowGC, 0, 0, rects, rectCount, YXBanded);

    QRect dirtyRect = widgetRegion.boundingRect().translated(-offset);
    XCopyArea(X11->display, m_backBuffer.handle(), m_window->handle(), m_windowGC,
              dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height(),
              dirtyRect.x(), dirtyRect.y());

    // Make sure the blit of the update from the back buffer to the window completes
    // before allowing rendering to start again to the back buffer. Otherwise the GPU
    // might start rendering to the back buffer again while the blit takes place.
    eglWaitNative(EGL_CORE_NATIVE_ENGINE);
}
Esempio n. 23
0
bool checkOpenGL(){

    QGLWidget *glWidget = new QGLWidget;

    QGLContext* glContext = (QGLContext *) glWidget->context();
    GLCHK( glContext->makeCurrent() );

    qDebug() << "Running the " + QString(AWESOME_BUMP_VERSION);
    qDebug() << "Checking OpenGL version...";
    qDebug() << "Widget OpenGL: " << glContext->format().majorVersion() << "." << glContext->format().minorVersion() ;
    qDebug() << "Context valid: " << glContext->isValid() ;
    qDebug() << "OpenGL information: " ;
    qDebug() << "VENDOR: "       << (const char*)glGetString(GL_VENDOR) ;
    qDebug() << "RENDERER: "     << (const char*)glGetString(GL_RENDERER) ;
    qDebug() << "VERSION: "      << (const char*)glGetString(GL_VERSION) ;
    qDebug() << "GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION) ;

    float version = glContext->format().majorVersion() + 0.1 * glContext->format().minorVersion();

    delete glWidget;

    qDebug() << "Version:" << version;
    // check openGL version
    if( version < 4.0 )
    {
       qDebug() << "Error: AwesomeBump does not support openGL versions lower than 4.0 :(" ;
       return false;
    }
    return true;

}
Esempio n. 24
0
QPixmap QX11GLWindowSurface::grabWidget(const QWidget *widget, const QRect& rect) const
{
    if (!widget || m_backBuffer.isNull())
        return QPixmap();

    QRect srcRect;

    // make sure the rect is inside the widget & clip to widget's rect
    if (!rect.isEmpty())
        srcRect = rect & widget->rect();
    else
        srcRect = widget->rect();

    if (srcRect.isEmpty())
        return QPixmap();

    // If it's a child widget we have to translate the coordinates
    if (widget != window())
        srcRect.translate(widget->mapTo(window(), QPoint(0, 0)));

    QPixmap::x11SetDefaultScreen(widget->x11Info().screen());

    QX11PixmapData *pmd = new QX11PixmapData(QPixmapData::PixmapType);
    pmd->resize(srcRect.width(), srcRect.height());
    QPixmap px(pmd);

    GC tmpGc = XCreateGC(X11->display, m_backBuffer.handle(), 0, 0);

    // Make sure all GL rendering is complete before copying the window
    QGLContext* ctx = static_cast<QX11GLPixmapData*>(m_backBuffer.pixmapData())->context();
    if (QGLContext::currentContext() != ctx && ctx && ctx->isValid())
        ctx->makeCurrent();
    eglWaitClient();

    // Copy srcRect from the backing store to the new pixmap
    XSetGraphicsExposures(X11->display, tmpGc, False);
    XCopyArea(X11->display, m_backBuffer.handle(), px.handle(), tmpGc,
              srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0);
    XFreeGC(X11->display, tmpGc);

    // Wait until the copy has finised before allowing more rendering into the back buffer
    eglWaitNative(EGL_CORE_NATIVE_ENGINE);

    return px;
}
Esempio n. 25
0
QList<VideoFrame::Format> GlslPainter::supportedFormats() const
{
    QList<VideoFrame::Format> formats;

    QGLContext *glContext = const_cast<QGLContext *>(QGLContext::currentContext());
    if (glContext) {
        glContext->makeCurrent();

        const QByteArray glExtensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
        if (QGLShaderProgram::hasOpenGLShaderPrograms(glContext)
                && glExtensions.contains("ARB_shader_objects")) {
            // We are usable.
            return formats << VideoFrame::Format_YV12
                           << VideoFrame::Format_RGB32;
        }
    }

    return formats;
}
Esempio n. 26
0
static PyObject *meth_QGLContext_reset(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QGLContext *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QGLContext, &sipCpp))
        {
            sipCpp->reset();

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QGLContext, sipName_reset, doc_QGLContext_reset);

    return NULL;
}
QPixmap* HostWindowDataOpenGL::acquirePixmap(QPixmap& screenPixmap)
{
	if (m_dirty) {
		m_dirty = false;
    
		m_ipcBuffer->lock();

		QGLContext* gc = (QGLContext*) QGLContext::currentContext();
		if (gc) {
            QImage data((uchar*) m_ipcBuffer->data(), m_width, m_height, QImage::Format_ARGB32_Premultiplied);
            screenPixmap = QPixmap::fromImage(data);
            // FIXME: is it really necessary to bind it here? Qt will bind it through
            // QGL2PaintEngineEx::drawPixmap -> QGLContextPrivate::bindTexture anyways
            m_textureId = gc->bindTexture(screenPixmap, GL_TEXTURE_2D, kGLInternalFormat,
                                          QGLContext::PremultipliedAlphaBindOption);
		}

		m_ipcBuffer->unlock();
	}

	return &screenPixmap;
}
Esempio n. 28
0
static PyObject *meth_QGLContext_setFormat(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        const QGLFormat* a0;
        QGLContext *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QGLContext, &sipCpp, sipType_QGLFormat, &a0))
        {
            sipCpp->setFormat(*a0);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QGLContext, sipName_setFormat, doc_QGLContext_setFormat);

    return NULL;
}
Esempio n. 29
0
static PyObject *meth_QGLContext_doneCurrent(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;
    bool sipSelfWasArg = (!sipSelf || sipIsDerived((sipSimpleWrapper *)sipSelf));

    {
        QGLContext *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QGLContext, &sipCpp))
        {
            (sipSelfWasArg ? sipCpp->QGLContext::doneCurrent() : sipCpp->doneCurrent());

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QGLContext, sipName_doneCurrent, doc_QGLContext_doneCurrent);

    return NULL;
}
Esempio n. 30
0
static PyObject *meth_QGLContext_deleteTexture(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        GLuint a0;
        QGLContext *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "Bu", &sipSelf, sipType_QGLContext, &sipCpp, &a0))
        {
            sipCpp->deleteTexture(a0);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QGLContext, sipName_deleteTexture, doc_QGLContext_deleteTexture);

    return NULL;
}