| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include <QtOpenGL/qgl.h> | 
|---|
| 43 | #include "qgl_egl_p.h" | 
|---|
| 44 |  | 
|---|
| 45 | QT_BEGIN_NAMESPACE | 
|---|
| 46 |  | 
|---|
| 47 | // Set device configuration attributes from a QGLFormat instance. | 
|---|
| 48 | void qt_egl_set_format(QEglProperties& props, int deviceType, const QGLFormat& f) | 
|---|
| 49 | { | 
|---|
| 50 | if (deviceType == QInternal::Pixmap || deviceType == QInternal::Image) | 
|---|
| 51 | props.setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT); | 
|---|
| 52 | else if (deviceType == QInternal::Pbuffer) | 
|---|
| 53 | props.setValue(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT); | 
|---|
| 54 | else | 
|---|
| 55 | props.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); | 
|---|
| 56 |  | 
|---|
| 57 | // Set the pixel format to that contained in the QGLFormat | 
|---|
| 58 | // if the system hasn't already chosen a fixed format to | 
|---|
| 59 | // match the pixmap, widget, etc. | 
|---|
| 60 | if (props.value(EGL_RED_SIZE) == EGL_DONT_CARE || f.redBufferSize() != -1) | 
|---|
| 61 | props.setValue(EGL_RED_SIZE, f.redBufferSize() == -1 ? 1 : f.redBufferSize()); | 
|---|
| 62 | if (props.value(EGL_GREEN_SIZE) == EGL_DONT_CARE || f.greenBufferSize() != -1) | 
|---|
| 63 | props.setValue(EGL_GREEN_SIZE, f.greenBufferSize() == -1 ? 1 : f.greenBufferSize()); | 
|---|
| 64 | if (props.value(EGL_BLUE_SIZE) == EGL_DONT_CARE || f.blueBufferSize() != -1) | 
|---|
| 65 | props.setValue(EGL_BLUE_SIZE, f.blueBufferSize() == -1 ? 1 : f.blueBufferSize()); | 
|---|
| 66 | if (f.alpha()) { | 
|---|
| 67 | if (props.value(EGL_ALPHA_SIZE) == EGL_DONT_CARE || f.alphaBufferSize() != -1) | 
|---|
| 68 | props.setValue(EGL_ALPHA_SIZE, f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize()); | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | if (f.depth()) | 
|---|
| 72 | props.setValue(EGL_DEPTH_SIZE, f.depthBufferSize() == -1 ? 1 : f.depthBufferSize()); | 
|---|
| 73 | if (f.stencil()) | 
|---|
| 74 | props.setValue(EGL_STENCIL_SIZE, f.stencilBufferSize() == -1 ? 1 : f.stencilBufferSize()); | 
|---|
| 75 | if (f.sampleBuffers()) { | 
|---|
| 76 | props.setValue(EGL_SAMPLE_BUFFERS, 1); | 
|---|
| 77 | props.setValue(EGL_SAMPLES, f.samples()); | 
|---|
| 78 | } else { | 
|---|
| 79 | props.setValue(EGL_SAMPLE_BUFFERS, 0); | 
|---|
| 80 | } | 
|---|
| 81 | if (deviceType == QInternal::Widget) | 
|---|
| 82 | props.setValue(EGL_LEVEL, f.plane()); | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | // Updates "format" with the parameters of the selected configuration. | 
|---|
| 86 | void qt_egl_update_format(const QEglContext& context, QGLFormat& format) | 
|---|
| 87 | { | 
|---|
| 88 | EGLint value = 0; | 
|---|
| 89 |  | 
|---|
| 90 | if (context.configAttrib(EGL_RED_SIZE, &value)) | 
|---|
| 91 | format.setRedBufferSize(value); | 
|---|
| 92 | if (context.configAttrib(EGL_GREEN_SIZE, &value)) | 
|---|
| 93 | format.setGreenBufferSize(value); | 
|---|
| 94 | if (context.configAttrib(EGL_BLUE_SIZE, &value)) | 
|---|
| 95 | format.setBlueBufferSize(value); | 
|---|
| 96 | if (context.configAttrib(EGL_ALPHA_SIZE, &value)) { | 
|---|
| 97 | format.setAlpha(value != 0); | 
|---|
| 98 | if (format.alpha()) | 
|---|
| 99 | format.setAlphaBufferSize(value); | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | if (context.configAttrib(EGL_DEPTH_SIZE, &value)) { | 
|---|
| 103 | format.setDepth(value != 0); | 
|---|
| 104 | if (format.depth()) | 
|---|
| 105 | format.setDepthBufferSize(value); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | if (context.configAttrib(EGL_LEVEL, &value)) | 
|---|
| 109 | format.setPlane(value); | 
|---|
| 110 |  | 
|---|
| 111 | if (context.configAttrib(EGL_SAMPLE_BUFFERS, &value)) { | 
|---|
| 112 | format.setSampleBuffers(value != 0); | 
|---|
| 113 | if (format.sampleBuffers()) { | 
|---|
| 114 | context.configAttrib(EGL_SAMPLES, &value); | 
|---|
| 115 | format.setSamples(value); | 
|---|
| 116 | } | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | if (context.configAttrib(EGL_STENCIL_SIZE, &value)) { | 
|---|
| 120 | format.setStencil(value != 0); | 
|---|
| 121 | if (format.stencil()) | 
|---|
| 122 | format.setStencilBufferSize(value); | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | // Clear the EGL error state because some of the above may | 
|---|
| 126 | // have errored out because the attribute is not applicable | 
|---|
| 127 | // to the surface type.  Such errors don't matter. | 
|---|
| 128 | context.clearError(); | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | QT_END_NAMESPACE | 
|---|