The patch introduces a new build configuration on Windows which can be requested by passing -opengl dynamic to configure. Platforms other than Windows (including WinRT) are not affected. The existing Angle and desktop configurations are not affected. These continue to function as before and Angle remains the default. In the future, when all modules have added support for the dynamic path, as described below, the default configuration could be changed to be the dynamic one. This would allow providing a single set of binaries in the official builds instead of the current two. When requesting dynamic GL, Angle is built but QT_OPENGL_ES[_2] are never defined. Instead, the code path that has traditionally been desktop GL only becomes the dynamic path that has to do runtime checks. Qt modules and applications are not linked to opengl32.dll or libegl/glesv2.dll in this case. Instead, QtGui exports all necessary egl/egl/gl functions which will, under the hood, forward all requests to a dynamically loaded EGL/WGL/GL implementation. Porting guide (better said, changes needed to prepare your code to work with dynamic GL builds when the fallback to Angle is utilized): 1. In !QT_OPENGL_ES[_2] code branches use QOpenGLFunctions::isES() to differentiate between desktop and ES where needed. Keep in mind that it is the desktop GL header (plus qopenglext.h) that is included, not the GLES one. QtGui's proxy will handle some differences, for example calling glClearDepth will route to glClearDepthf when needed. The built-in eglGetProcAddress is able to retrieve pointers for standard GLES2 functions too so code resolving OpenGL 2 functions will function in any case. 2. QT_CONFIG will contain "opengl" and "dynamicgl" in dynamic builds, but never "angle" or "opengles2". 3. The preprocessor define QT_OPENGL_DYNAMIC is also available in dynamic builds. The usage of this is strongly discouraged and should not be needed anywhere except for QtGui and the platform plugin. 4. Code in need of the library handle can use QOpenGLFunctions::platformGLHandle(). The decision on which library to load is currently based on a simple test that creates a dummy window/context and tries to resolve an OpenGL 2 function. If this fails, it goes for Angle. This seems to work well on Win7 PCs for example that do not have proper graphics drivers providing OpenGL installed but are D3D9 capable using the default drivers. Setting QT_OPENGL to desktop or angle skips the test and forces usage of the given GL. There are also two new application attributes that could be used for the same purpose. If Angle is requested but the libraries are not present, desktop is tried. If desktop is requested, or if angle is requested but nothing works, the EGL/WGL functions will still be callable but will return 0. This conveniently means that eglInitialize() and such will report a failure. Debug messages can be enabled by setting QT_OPENGLPROXY_DEBUG. This will tell which implementation is chosen. The textures example application is ported to OpenGL 2, the GL 1 code path is removed. [ChangeLog][QtGui] Qt builds on Windows can now be configured for dynamic loading of the OpenGL implementation. This can be requested by passing -opengl dynamic to configure. In this mode no modules will link to opengl32.dll or Angle's libegl/libglesv2. Instead, QtGui will dynamically choose between desktop and Angle during the first GL/EGL/WGL call. This allows deploying applications with a single set of Qt libraries with the ability of transparently falling back to Angle in case the opengl32.dll is not suitable, due to missing graphics drivers for example. Task-number: QTBUG-36483 Change-Id: I716fdebbf60b355b7d9ef57d1e069eef366b4ab9 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
292 lines
8.8 KiB
C
292 lines
8.8 KiB
C
/****************************************************************************
|
|
**
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
** Contact: http://www.qt-project.org/legal
|
|
**
|
|
** This file is part of the QtGui module of the Qt Toolkit.
|
|
**
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
** Commercial License Usage
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
** accordance with the commercial license agreement provided with the
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
**
|
|
** GNU Lesser General Public License Usage
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
** General Public License version 2.1 as published by the Free Software
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
** packaging of this file. Please review the following information to
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
**
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
**
|
|
** GNU General Public License Usage
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
** General Public License version 3.0 as published by the Free Software
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
** packaging of this file. Please review the following information to
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
|
**
|
|
**
|
|
** $QT_END_LICENSE$
|
|
**
|
|
****************************************************************************/
|
|
|
|
#ifndef QOPENGL_H
|
|
#define QOPENGL_H
|
|
|
|
#include <QtCore/qglobal.h>
|
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
// Windows always needs this to ensure that APIENTRY gets defined
|
|
#if defined(Q_OS_WIN)
|
|
# include <QtCore/qt_windows.h>
|
|
#endif
|
|
|
|
// Note: Mac OSX is a "controlled platform" for OpenGL ABI so we
|
|
// use the system provided headers there. Controlled means that the
|
|
// headers always match the actual driver implementation so there
|
|
// is no possibility of drivers exposing additional functionality
|
|
// from the system headers. Also it means that the vendor can
|
|
// (and does) make different choices about some OpenGL types. For
|
|
// e.g. Apple uses void* for GLhandleARB whereas other platforms
|
|
// use unsigned int.
|
|
//
|
|
// For the "uncontrolled" Windows and Linux platforms we use the
|
|
// official Khronos headers. On these platforms this gives
|
|
// access to additional functionality the drivers may expose but
|
|
// which the system headers do not.
|
|
|
|
#if defined(QT_OPENGL_ES_2)
|
|
# if defined(Q_OS_MAC)
|
|
# include <OpenGLES/ES2/gl.h>
|
|
# include <OpenGLES/ES2/glext.h>
|
|
|
|
/*
|
|
OES_EGL_image_external is not included in the Apple provided
|
|
system headers yet, but we define the missing typedef so that
|
|
the qopenglextensions.cpp code will magically work once Apple
|
|
include the extension in their drivers.
|
|
*/
|
|
typedef void* GLeglImageOES;
|
|
|
|
# else // "uncontrolled" platforms
|
|
# include <GLES2/gl2.h>
|
|
|
|
/*
|
|
Some GLES2 implementations (like the one on Harmattan) are missing the
|
|
typedef for GLchar. Work around it here by adding it. The Kkronos headers
|
|
specify GLChar as a typedef to char, so if an implementation already
|
|
provides it, then this doesn't do any harm.
|
|
*/
|
|
typedef char GLchar;
|
|
|
|
# include <QtGui/qopengles2ext.h>
|
|
# ifndef GL_DOUBLE
|
|
# define GL_DOUBLE GL_FLOAT
|
|
# endif
|
|
# ifndef GLdouble
|
|
typedef GLfloat GLdouble;
|
|
# endif
|
|
# endif // Q_OS_MAC
|
|
#else
|
|
# if defined(Q_OS_MAC)
|
|
# include <OpenGL/gl.h>
|
|
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
|
# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
|
|
# include <OpenGL/gl3.h>
|
|
# endif
|
|
# include <OpenGL/glext.h>
|
|
# else
|
|
# define GL_GLEXT_LEGACY // Prevents GL/gl.h from #including system glext.h
|
|
// In dynamic GL builds qopenglproxy will export the GL functions that are
|
|
// called also in QtGui itself. To prevent linker warnings (msvc) or errors (mingw)
|
|
// we need to make sure the prototypes do not have dllimport.
|
|
# ifdef QT_OPENGL_DYNAMIC_IN_GUI
|
|
# undef WINGDIAPI
|
|
# define WINGDIAPI
|
|
# endif // QT_OPENGL_DYNAMIC_IN_GUI
|
|
# include <GL/gl.h>
|
|
# ifdef QT_OPENGL_DYNAMIC_IN_GUI
|
|
# undef WINGDIAPI
|
|
# endif // QT_OPENGL_DYNAMIC_IN_GUI
|
|
# include <QtGui/qopenglext.h>
|
|
# endif // Q_OS_MAC
|
|
#endif
|
|
|
|
// Desktops, apart from Mac OS X prior to 10.7 can support OpenGL 3
|
|
// and desktops apart from Mac can support OpenGL 4
|
|
#if !defined(QT_OPENGL_ES_2)
|
|
# if !defined(Q_OS_MAC) || (defined(Q_OS_MAC) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
|
|
# define QT_OPENGL_3
|
|
# define QT_OPENGL_3_2
|
|
# endif
|
|
#if !defined(Q_OS_MAC)
|
|
# define QT_OPENGL_4
|
|
# define QT_OPENGL_4_3
|
|
#endif
|
|
#endif
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
// When all else fails we provide sensible fallbacks - this is needed to
|
|
// allow compilation on OS X 10.6
|
|
#if !defined(QT_OPENGL_ES_2)
|
|
|
|
// OS X 10.6 doesn't define these which are needed below
|
|
// OS X 10.7 and later defien them in gl3.h
|
|
#ifndef APIENTRY
|
|
#define APIENTRY
|
|
#endif
|
|
#ifndef APIENTRYP
|
|
#define APIENTRYP APIENTRY *
|
|
#endif
|
|
#ifndef GLAPI
|
|
#define GLAPI extern
|
|
#endif
|
|
|
|
|
|
// This block is copied from glext.h and defines the types needed by
|
|
// a few extension classes.
|
|
|
|
#include <stddef.h>
|
|
#ifndef GL_VERSION_2_0
|
|
/* GL type for program/shader text */
|
|
typedef char GLchar;
|
|
#endif
|
|
|
|
#ifndef GL_VERSION_1_5
|
|
/* GL types for handling large vertex buffer objects */
|
|
typedef ptrdiff_t GLintptr;
|
|
typedef ptrdiff_t GLsizeiptr;
|
|
#endif
|
|
|
|
#ifndef GL_ARB_vertex_buffer_object
|
|
/* GL types for handling large vertex buffer objects */
|
|
typedef ptrdiff_t GLintptrARB;
|
|
typedef ptrdiff_t GLsizeiptrARB;
|
|
#endif
|
|
|
|
#ifndef GL_ARB_shader_objects
|
|
/* GL types for program/shader text and shader object handles */
|
|
typedef char GLcharARB;
|
|
typedef unsigned int GLhandleARB;
|
|
#endif
|
|
|
|
/* GL type for "half" precision (s10e5) float data in host memory */
|
|
#ifndef GL_ARB_half_float_pixel
|
|
typedef unsigned short GLhalfARB;
|
|
#endif
|
|
|
|
#ifndef GL_NV_half_float
|
|
typedef unsigned short GLhalfNV;
|
|
#endif
|
|
|
|
#ifndef GLEXT_64_TYPES_DEFINED
|
|
/* This code block is duplicated in glxext.h, so must be protected */
|
|
#define GLEXT_64_TYPES_DEFINED
|
|
/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
|
|
/* (as used in the GL_EXT_timer_query extension). */
|
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
|
#include <inttypes.h>
|
|
#elif defined(__sun__) || defined(__digital__)
|
|
#include <inttypes.h>
|
|
#if defined(__STDC__)
|
|
#if defined(__arch64__) || defined(_LP64)
|
|
typedef long int int64_t;
|
|
typedef unsigned long int uint64_t;
|
|
#else
|
|
typedef long long int int64_t;
|
|
typedef unsigned long long int uint64_t;
|
|
#endif /* __arch64__ */
|
|
#endif /* __STDC__ */
|
|
#elif defined( __VMS ) || defined(__sgi)
|
|
#include <inttypes.h>
|
|
#elif defined(__SCO__) || defined(__USLC__)
|
|
#include <stdint.h>
|
|
#elif defined(__UNIXOS2__) || defined(__SOL64__)
|
|
typedef long int int32_t;
|
|
typedef long long int int64_t;
|
|
typedef unsigned long long int uint64_t;
|
|
#elif defined(_WIN32) && defined(__GNUC__)
|
|
#include <stdint.h>
|
|
#elif defined(_WIN32)
|
|
typedef __int32 int32_t;
|
|
typedef __int64 int64_t;
|
|
typedef unsigned __int64 uint64_t;
|
|
#else
|
|
/* Fallback if nothing above works */
|
|
#include <inttypes.h>
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef GL_EXT_timer_query
|
|
typedef int64_t GLint64EXT;
|
|
typedef uint64_t GLuint64EXT;
|
|
#endif
|
|
|
|
#ifndef GL_ARB_sync
|
|
typedef int64_t GLint64;
|
|
typedef uint64_t GLuint64;
|
|
typedef struct __GLsync *GLsync;
|
|
#endif
|
|
|
|
#ifndef GL_ARB_cl_event
|
|
/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */
|
|
struct _cl_context;
|
|
struct _cl_event;
|
|
#endif
|
|
|
|
#ifndef GL_ARB_debug_output
|
|
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
|
|
#endif
|
|
|
|
#ifndef GL_AMD_debug_output
|
|
typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
|
|
#endif
|
|
|
|
#ifndef GL_KHR_debug
|
|
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
|
|
#endif
|
|
|
|
#ifndef GL_NV_vdpau_interop
|
|
typedef GLintptr GLvdpauSurfaceNV;
|
|
#endif
|
|
|
|
// End of block copied from glext.h
|
|
#endif
|
|
|
|
|
|
// Types that aren't defined in all system's gl.h files.
|
|
typedef ptrdiff_t qopengl_GLintptr;
|
|
typedef ptrdiff_t qopengl_GLsizeiptr;
|
|
|
|
|
|
#if defined(APIENTRY) && !defined(QOPENGLF_APIENTRY)
|
|
# define QOPENGLF_APIENTRY APIENTRY
|
|
#endif
|
|
|
|
# ifndef QOPENGLF_APIENTRYP
|
|
# ifdef QOPENGLF_APIENTRY
|
|
# define QOPENGLF_APIENTRYP QOPENGLF_APIENTRY *
|
|
# else
|
|
# define QOPENGLF_APIENTRY
|
|
# define QOPENGLF_APIENTRYP *
|
|
# endif
|
|
# endif
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
#endif // QT_NO_OPENGL
|
|
|
|
#endif // QOPENGL_H
|