1/**************************************************************************** 2** 3** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB) 4** Contact: https://www.qt.io/licensing/ 5** 6** This file is part of the QtGui module of the Qt Toolkit. 7** 8** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see https://www.qt.io/terms-conditions. For further 15** information use the contact form at https://www.qt.io/contact-us. 16** 17** GNU General Public License Usage 18** Alternatively, this file may be used under the terms of the GNU 19** General Public License version 3 as published by the Free Software 20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21** included in the packaging of this file. Please review the following 22** information to ensure the GNU General Public License requirements will 23** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24** 25** $QT_END_LICENSE$ 26** 27** 28** This file was generated by glgen version 0.1 29** Command line was: glgen 30** 31** glgen is Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB) 32** 33** This is an auto-generated file. 34** Do not edit! All changes made to it will be lost. 35** 36****************************************************************************/ 37 38#include "qopenglversionfunctions.h" 39#include "qopenglcontext.h" 40#include "qdebug.h" 41 42QT_BEGIN_NAMESPACE 43 44QOpenGLVersionFunctionsBackend *QAbstractOpenGLFunctionsPrivate::functionsBackend(QOpenGLContext *context, 45 const QOpenGLVersionStatus &v) 46{ 47 Q_ASSERT(context); 48 return context->functionsBackend(v); 49} 50 51void QAbstractOpenGLFunctionsPrivate::insertFunctionsBackend(QOpenGLContext *context, 52 const QOpenGLVersionStatus &v, 53 QOpenGLVersionFunctionsBackend *backend) 54{ 55 Q_ASSERT(context); 56 context->insertFunctionsBackend(v, backend); 57} 58 59void QAbstractOpenGLFunctionsPrivate::removeFunctionsBackend(QOpenGLContext *context, const QOpenGLVersionStatus &v) 60{ 61 Q_ASSERT(context); 62 context->removeFunctionsBackend(v); 63} 64 65 66/*! 67 \class QAbstractOpenGLFunctions 68 \inmodule QtGui 69 \since 5.1 70 \brief The QAbstractOpenGLFunctions class is the base class of a family of 71 classes that expose all functions for each OpenGL version and 72 profile. 73 74 OpenGL implementations on different platforms are able to link to a variable 75 number of OpenGL functions depending upon the OpenGL ABI on that platform. 76 For example, on Microsoft Windows only functions up to those in OpenGL 1.1 77 can be linked to at build time. All other functions must be resolved at 78 runtime. The traditional solution to this has been to use either 79 QOpenGLContext::getProcAddress() or QOpenGLFunctions. The former is tedious 80 and error prone and means dealing directly with function pointers. The 81 latter only exposes those functions common to OpenGL ES 2 and desktop 82 OpenGL. There is however much new OpenGL functionality that is useful when 83 writing real world OpenGL applications. 84 85 Qt now provides a family of classes which all inherit from 86 QAbstractOpenGLFunctions which expose every core OpenGL function by way of a 87 corresponding member function. There is a class for every valid combination 88 of OpenGL version and profile. Each class follows the naming convention 89 QOpenGLFunctions_<MAJOR VERSION>_<MINOR VERSION>[_PROFILE]. 90 91 For OpenGL versions 1.0 through to 3.0 there are no profiles, leading to the 92 classes: 93 94 \list 95 \li QOpenGLFunctions_1_0 96 \li QOpenGLFunctions_1_1 97 \li QOpenGLFunctions_1_2 98 \li QOpenGLFunctions_1_3 99 \li QOpenGLFunctions_1_4 100 \li QOpenGLFunctions_1_5 101 \li QOpenGLFunctions_2_0 102 \li QOpenGLFunctions_2_1 103 \li QOpenGLFunctions_3_0 104 \endlist 105 106 where each class inherits from QAbstractOpenGLFunctions. 107 108 OpenGL version 3.1 removed many deprecated functions leading to a much 109 simpler and generic API. 110 111 With OpenGL 3.2 the concept of profiles was introduced. Two profiles are 112 currently defined for OpenGL: Core and Compatibility. 113 114 The Core profile does not include any of the functions that were removed 115 in OpenGL 3.1. The Compatibility profile contains all functions in the 116 Core profile of the same version plus all of the functions that were 117 removed in OpenGL 3.1. In this way the Compatibility profile classes allow 118 use of newer OpenGL functionality but also allows you to keep using your 119 legacy OpenGL code. For new OpenGL code the Core profile should be 120 preferred. 121 122 Please note that some vendors, notably Apple, do not implement the 123 Compatibility profile. Therefore if you wish to target new OpenGL features 124 on OS X then you should ensure that you request a Core profile context via 125 QSurfaceFormat::setProfile(). 126 127 Qt provides classes for all version and Core and Compatibility profile 128 combinations. The classes for OpenGL versions 3.1 through to 4.3 are: 129 130 \list 131 \li QOpenGLFunctions_3_1 132 \li QOpenGLFunctions_3_2_Core 133 \li QOpenGLFunctions_3_2_Compatibility 134 \li QOpenGLFunctions_3_3_Core 135 \li QOpenGLFunctions_3_3_Compatibility 136 \li QOpenGLFunctions_4_0_Core 137 \li QOpenGLFunctions_4_0_Compatibility 138 \li QOpenGLFunctions_4_1_Core 139 \li QOpenGLFunctions_4_1_Compatibility 140 \li QOpenGLFunctions_4_2_Core 141 \li QOpenGLFunctions_4_2_Compatibility 142 \li QOpenGLFunctions_4_3_Core 143 \li QOpenGLFunctions_4_3_Compatibility 144 \endlist 145 146 where each class inherits from QAbstractOpenGLFunctions. 147 148 A pointer to an object of the class corresponding to the version and 149 profile of OpenGL in use can be obtained from 150 QOpenGLFunctions::versionFunctions(). If obtained in this way, note that 151 the QOpenGLContext retains ownership of the object. This is so that only 152 one instance need be created. 153 154 Before calling any of the exposed OpenGL functions you must ensure that the 155 object has resolved the function pointers to the OpenGL functions. This 156 only needs to be done once per instance with initializeOpenGLFunctions(). 157 Once initialized, the object can be used to call any OpenGL function for 158 the corresponding version and profile. Note that initializeOpenGLFunctions() 159 can fail in some circumstances so check the return value. Situations in 160 which initialization can fail are if you have a functions object for a version 161 or profile that contains functions that are not part of the context being 162 used to resolve the function pointers. 163 164 If you exclusively use function objects then you will get compile time 165 errors if you attempt to use a function not included in that version and 166 profile. This is obviously a lot easier to debug than undefined behavior 167 at run time. 168 169 \sa QOpenGLContext::versionFunctions() 170*/ 171QAbstractOpenGLFunctions::QAbstractOpenGLFunctions() 172 : d_ptr(new QAbstractOpenGLFunctionsPrivate) 173{ 174} 175 176QAbstractOpenGLFunctions::~QAbstractOpenGLFunctions() 177{ 178 delete d_ptr; 179} 180 181bool QAbstractOpenGLFunctions::initializeOpenGLFunctions() 182{ 183 Q_D(QAbstractOpenGLFunctions); 184 d->initialized = true; 185 return true; 186} 187 188bool QAbstractOpenGLFunctions::isInitialized() const 189{ 190 Q_D(const QAbstractOpenGLFunctions); 191 return d->initialized; 192} 193 194void QAbstractOpenGLFunctions::setOwningContext(const QOpenGLContext *context) 195{ 196 Q_D(QAbstractOpenGLFunctions); 197 d->owningContext = const_cast<QOpenGLContext*>(context); 198} 199 200QOpenGLContext *QAbstractOpenGLFunctions::owningContext() const 201{ 202 Q_D(const QAbstractOpenGLFunctions); 203 return d->owningContext; 204} 205 206#if !defined(QT_OPENGL_ES_2) 207 208