Example #1
0
void OpenGL2Common::testGLInternal()
{
	int glMajor = 0, glMinor = 0;
#ifndef OPENGL_ES2
	glGetIntegerv(GL_MAJOR_VERSION, &glMajor);
	glGetIntegerv(GL_MINOR_VERSION, &glMinor);
#endif
	if (!glMajor)
	{
		const QString glVersionStr = (const char *)glGetString(GL_VERSION);
		const int dotIdx = glVersionStr.indexOf('.');
		if (dotIdx > 0)
		{
			const int vIdx = glVersionStr.lastIndexOf(' ', dotIdx);
			if (sscanf(glVersionStr.mid(vIdx < 0 ? 0 : vIdx).toLatin1().data(), "%d.%d", &glMajor, &glMinor) != 2)
				glMajor = glMinor = 0;
		}
	}
	if (glMajor)
		glVer = glMajor * 10 + glMinor;

#ifndef OPENGL_ES2
	initGLProc();
	if (!canCreateNonPowerOfTwoTextures || !supportsShaders || !glActiveTexture)
	{
		showOpenGLMissingFeaturesMessage();
		isOK = false;
	}
	/* Reset variables */
	supportsShaders = canCreateNonPowerOfTwoTextures = false;
	glActiveTexture = NULL;
#endif

	QWidget *w = widget();
	w->grabGesture(Qt::PinchGesture);
	w->setMouseTracking(true);
#ifdef Q_OS_WIN
	/*
	 * This property is read by QMPlay2 and it ensures that toolbar will be visible
	 * on fullscreen in Windows Vista and newer on nVidia and AMD drivers.
	*/
	if (preventFullscreen && QSysInfo::windowsVersion() >= QSysInfo::WV_6_0)
		w->setProperty("PreventFullscreen", true);
#endif
}
Example #2
0
void OpenGL2Common::testGLInternal()
{
    int glMajor = 0, glMinor = 0;
#ifndef OPENGL_ES2
    glGetIntegerv(GL_MAJOR_VERSION, &glMajor);
    glGetIntegerv(GL_MINOR_VERSION, &glMinor);
#endif
#ifndef Q_OS_MACOS //On macOS I have always OpenGL 2.1...
    if (!glMajor)
    {
        const QString glVersionStr = (const char *)glGetString(GL_VERSION);
        const int dotIdx = glVersionStr.indexOf('.');
        if (dotIdx > 0)
        {
            const int vIdx = glVersionStr.lastIndexOf(' ', dotIdx);
            if (sscanf(glVersionStr.mid(vIdx < 0 ? 0 : vIdx).toLatin1().constData(), "%d.%d", &glMajor, &glMinor) != 2)
                glMajor = glMinor = 0;
        }
    }
    if (glMajor)
        glVer = glMajor * 10 + glMinor;
    canUseHueSharpness = (glVer >= 30);
#endif

#ifndef OPENGL_ES2
    initGLProc(); //No need to call it here for OpenGL|ES
    if (!canCreateNonPowerOfTwoTextures || !supportsShaders || !glActiveTexture)
    {
        showOpenGLMissingFeaturesMessage();
        isOK = false;
    }
    /* Reset variables */
    supportsShaders = canCreateNonPowerOfTwoTextures = false;
    glActiveTexture = nullptr;
#endif

    numPlanes = 3;
    target = GL_TEXTURE_2D;
    if (hwAccellnterface)
    {
        switch (hwAccellnterface->getFormat())
        {
            case HWAccelInterface::NV12:
                numPlanes = 2;
                break;
            case HWAccelInterface::RGB32:
                numPlanes = 1;
                break;
        }

        if (hwAccellnterface->isTextureRectangle())
        {
            target = GL_TEXTURE_RECTANGLE_ARB;
            if (numPlanes == 1)
                isOK = false; // Not used and not supported
            hqScaling = false; // Not yet supported
        }

        if (isOK)
        {
            quint32 textures[numPlanes];
            memset(textures, 0, sizeof textures);
            glGenTextures(numPlanes, textures);
            if (hwAccellnterface->canInitializeTextures())
            {
                for (int p = 0; p < numPlanes; ++p)
                {
                    glBindTexture(target, textures[p]);
                    if (numPlanes == 2)
                        glTexImage2D(target, 0, !p ? GL_R8 : GL_RG8, 1, 1, 0, !p ? GL_RED : GL_RG, GL_UNSIGNED_BYTE, nullptr);
                    else if (numPlanes == 1)
                        glTexImage2D(target, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
                }
            }

            if (!hwAccellnterface->lock())
                isOK = false;
            else
            {
                if (!hwAccellnterface->init(textures))
                    isOK = false;
                if (numPlanes == 1) //For RGB32 format, HWAccel should be able to adjust the video
                {
                    VideoAdjustment videoAdjustmentCap;
                    hwAccellnterface->getVideAdjustmentCap(videoAdjustmentCap);
                    if (videoAdjustmentCap.brightness)
                        videoAdjustmentKeys += "Brightness";
                    if (videoAdjustmentCap.contrast)
                        videoAdjustmentKeys += "Contrast";
                    if (videoAdjustmentCap.saturation)
                        videoAdjustmentKeys += "Saturation";
                    if (videoAdjustmentCap.hue)
                        videoAdjustmentKeys += "Hue";
                    if (videoAdjustmentCap.sharpness)
                        videoAdjustmentKeys += "Sharpness";
                }
                hwAccellnterface->clear(true);
                hwAccellnterface->unlock();
            }

            glDeleteTextures(numPlanes, textures);
        }
    }

    QWidget *w = widget();
    w->grabGesture(Qt::PinchGesture);
    w->setMouseTracking(true);
#ifdef Q_OS_WIN
    /*
     * This property is read by QMPlay2 and it ensures that toolbar will be visible
     * on fullscreen in Windows Vista and newer on nVidia and AMD drivers.
    */
    const bool canPreventFullScreen = (qstrcmp(w->metaObject()->className(), "QOpenGLWidget") != 0);
    const QSysInfo::WinVersion winVer = QSysInfo::windowsVersion();
    if (canPreventFullScreen && winVer >= QSysInfo::WV_6_0)
    {
        Qt::CheckState compositionEnabled;
        if (!preventFullScreen)
            compositionEnabled = Qt::PartiallyChecked;
        else
        {
            compositionEnabled = Qt::Checked;
            if (winVer <= QSysInfo::WV_6_1) //Windows 8 and 10 can't disable DWM composition
            {
                using DwmIsCompositionEnabledProc = HRESULT (WINAPI *)(BOOL *pfEnabled);
                DwmIsCompositionEnabledProc DwmIsCompositionEnabled = (DwmIsCompositionEnabledProc)GetProcAddress(GetModuleHandleA("dwmapi.dll"), "DwmIsCompositionEnabled");
                if (DwmIsCompositionEnabled)
                {
                    BOOL enabled = false;
                    if (DwmIsCompositionEnabled(&enabled) == S_OK && !enabled)
                        compositionEnabled = Qt::PartiallyChecked;
                }
            }
        }
        w->setProperty("preventFullScreen", (int)compositionEnabled);
    }
#endif
}