Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the Qt Quick module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
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 Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qsgdepthstencilbuffer_p.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | QT_BEGIN_NAMESPACE | - | ||||||||||||
43 | - | |||||||||||||
44 | QSGDepthStencilBuffer::QSGDepthStencilBuffer(QOpenGLContext *context, const Format &format) | - | ||||||||||||
45 | : m_functions(context) | - | ||||||||||||
46 | , m_manager(nullptr) | - | ||||||||||||
47 | , m_format(format) | - | ||||||||||||
48 | , m_depthBuffer(0) | - | ||||||||||||
49 | , m_stencilBuffer(0) | - | ||||||||||||
50 | { | - | ||||||||||||
51 | // 'm_manager' is set by QSGDepthStencilBufferManager::insertBuffer(). | - | ||||||||||||
52 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
53 | - | |||||||||||||
54 | QSGDepthStencilBuffer::~QSGDepthStencilBuffer() | - | ||||||||||||
55 | { | - | ||||||||||||
56 | if (m_manager)
| 0-67 | ||||||||||||
57 | m_manager->m_buffers.remove(m_format); executed 67 times by 5 tests: m_manager->m_buffers.remove(m_format); Executed by:
| 67 | ||||||||||||
58 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
59 | - | |||||||||||||
60 | void QSGDepthStencilBuffer::attach() | - | ||||||||||||
61 | { | - | ||||||||||||
62 | m_functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | - | ||||||||||||
63 | GL_RENDERBUFFER, m_depthBuffer); | - | ||||||||||||
64 | m_functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, | - | ||||||||||||
65 | GL_RENDERBUFFER, m_stencilBuffer); | - | ||||||||||||
66 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||
67 | - | |||||||||||||
68 | void QSGDepthStencilBuffer::detach() | - | ||||||||||||
69 | { | - | ||||||||||||
70 | m_functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | - | ||||||||||||
71 | GL_RENDERBUFFER, 0); | - | ||||||||||||
72 | m_functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, | - | ||||||||||||
73 | GL_RENDERBUFFER, 0); | - | ||||||||||||
74 | } executed 85 times by 5 tests: end of block Executed by:
| 85 | ||||||||||||
75 | - | |||||||||||||
76 | #ifndef GL_DEPTH24_STENCIL8_OES | - | ||||||||||||
77 | #define GL_DEPTH24_STENCIL8_OES 0x88F0 | - | ||||||||||||
78 | #endif | - | ||||||||||||
79 | - | |||||||||||||
80 | #ifndef GL_DEPTH_COMPONENT24_OES | - | ||||||||||||
81 | #define GL_DEPTH_COMPONENT24_OES 0x81A6 | - | ||||||||||||
82 | #endif | - | ||||||||||||
83 | - | |||||||||||||
84 | QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *context, const Format &format) | - | ||||||||||||
85 | : QSGDepthStencilBuffer(context, format) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | const GLsizei width = format.size.width(); | - | ||||||||||||
88 | const GLsizei height = format.size.height(); | - | ||||||||||||
89 | - | |||||||||||||
90 | if (format.attachments == (DepthAttachment | StencilAttachment)
| 0-67 | ||||||||||||
91 | && m_functions.hasOpenGLExtension(QOpenGLExtensions::PackedDepthStencil))
| 0-67 | ||||||||||||
92 | { | - | ||||||||||||
93 | m_functions.glGenRenderbuffers(1, &m_depthBuffer); | - | ||||||||||||
94 | m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer); | - | ||||||||||||
95 | if (format.samples && m_functions.hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) {
| 0-67 | ||||||||||||
96 | #if defined(QT_OPENGL_ES_2) | - | ||||||||||||
97 | m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples, | - | ||||||||||||
98 | GL_DEPTH24_STENCIL8_OES, width, height); | - | ||||||||||||
99 | #else | - | ||||||||||||
100 | m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples, | - | ||||||||||||
101 | GL_DEPTH24_STENCIL8, width, height); | - | ||||||||||||
102 | #endif | - | ||||||||||||
103 | } else { never executed: end of block | 0 | ||||||||||||
104 | #if defined(QT_OPENGL_ES_2) | - | ||||||||||||
105 | m_functions.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height); | - | ||||||||||||
106 | #else | - | ||||||||||||
107 | m_functions.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); | - | ||||||||||||
108 | #endif | - | ||||||||||||
109 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
110 | m_stencilBuffer = m_depthBuffer; | - | ||||||||||||
111 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
112 | if (!m_depthBuffer && (format.attachments & DepthAttachment)) {
| 0-67 | ||||||||||||
113 | m_functions.glGenRenderbuffers(1, &m_depthBuffer); | - | ||||||||||||
114 | m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer); | - | ||||||||||||
115 | GLenum internalFormat = GL_DEPTH_COMPONENT; | - | ||||||||||||
116 | if (context->isOpenGLES())
| 0 | ||||||||||||
117 | internalFormat = m_functions.hasOpenGLExtension(QOpenGLExtensions::Depth24) never executed: internalFormat = m_functions.hasOpenGLExtension(QOpenGLExtensions::Depth24) ? 0x81A6 : 0x81A5;
| 0 | ||||||||||||
118 | ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16; never executed: internalFormat = m_functions.hasOpenGLExtension(QOpenGLExtensions::Depth24) ? 0x81A6 : 0x81A5; | 0 | ||||||||||||
119 | if (format.samples && m_functions.hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) {
| 0 | ||||||||||||
120 | m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples, | - | ||||||||||||
121 | internalFormat, width, height); | - | ||||||||||||
122 | } else { never executed: end of block | 0 | ||||||||||||
123 | m_functions.glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, width, height); | - | ||||||||||||
124 | } never executed: end of block | 0 | ||||||||||||
125 | } | - | ||||||||||||
126 | if (!m_stencilBuffer && (format.attachments & StencilAttachment)) {
| 0-67 | ||||||||||||
127 | m_functions.glGenRenderbuffers(1, &m_stencilBuffer); | - | ||||||||||||
128 | m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer); | - | ||||||||||||
129 | #ifdef QT_OPENGL_ES | - | ||||||||||||
130 | const GLenum internalFormat = GL_STENCIL_INDEX8; | - | ||||||||||||
131 | #else | - | ||||||||||||
132 | const GLenum internalFormat = context->isOpenGLES() ? GL_STENCIL_INDEX8 : GL_STENCIL_INDEX;
| 0 | ||||||||||||
133 | #endif | - | ||||||||||||
134 | if (format.samples && m_functions.hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) {
| 0 | ||||||||||||
135 | m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples, | - | ||||||||||||
136 | internalFormat, width, height); | - | ||||||||||||
137 | } else { never executed: end of block | 0 | ||||||||||||
138 | m_functions.glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, width, height); | - | ||||||||||||
139 | } never executed: end of block | 0 | ||||||||||||
140 | } | - | ||||||||||||
141 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
142 | - | |||||||||||||
143 | QSGDefaultDepthStencilBuffer::~QSGDefaultDepthStencilBuffer() | - | ||||||||||||
144 | { | - | ||||||||||||
145 | free(); | - | ||||||||||||
146 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
147 | - | |||||||||||||
148 | void QSGDefaultDepthStencilBuffer::free() | - | ||||||||||||
149 | { | - | ||||||||||||
150 | if (m_depthBuffer)
| 0-67 | ||||||||||||
151 | m_functions.glDeleteRenderbuffers(1, &m_depthBuffer); executed 67 times by 5 tests: m_functions.glDeleteRenderbuffers(1, &m_depthBuffer); Executed by:
| 67 | ||||||||||||
152 | if (m_stencilBuffer && m_stencilBuffer != m_depthBuffer)
| 0-67 | ||||||||||||
153 | m_functions.glDeleteRenderbuffers(1, &m_stencilBuffer); never executed: m_functions.glDeleteRenderbuffers(1, &m_stencilBuffer); | 0 | ||||||||||||
154 | m_depthBuffer = m_stencilBuffer = 0; | - | ||||||||||||
155 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
156 | - | |||||||||||||
157 | - | |||||||||||||
158 | QSGDepthStencilBufferManager::~QSGDepthStencilBufferManager() | - | ||||||||||||
159 | { | - | ||||||||||||
160 | for (Hash::const_iterator it = m_buffers.constBegin(), cend = m_buffers.constEnd(); it != cend; ++it) {
| 0-57 | ||||||||||||
161 | QSGDepthStencilBuffer *buffer = it.value().data(); | - | ||||||||||||
162 | buffer->free(); | - | ||||||||||||
163 | buffer->m_manager = nullptr; | - | ||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||
165 | } executed 57 times by 5 tests: end of block Executed by:
| 57 | ||||||||||||
166 | - | |||||||||||||
167 | QSharedPointer<QSGDepthStencilBuffer> QSGDepthStencilBufferManager::bufferForFormat(const QSGDepthStencilBuffer::Format &fmt) | - | ||||||||||||
168 | { | - | ||||||||||||
169 | Hash::const_iterator it = m_buffers.constFind(fmt); | - | ||||||||||||
170 | if (it != m_buffers.constEnd())
| 18-67 | ||||||||||||
171 | return it.value().toStrongRef(); executed 18 times by 2 tests: return it.value().toStrongRef(); Executed by:
| 18 | ||||||||||||
172 | return QSharedPointer<QSGDepthStencilBuffer>(); executed 67 times by 5 tests: return QSharedPointer<QSGDepthStencilBuffer>(); Executed by:
| 67 | ||||||||||||
173 | } | - | ||||||||||||
174 | - | |||||||||||||
175 | void QSGDepthStencilBufferManager::insertBuffer(const QSharedPointer<QSGDepthStencilBuffer> &buffer) | - | ||||||||||||
176 | { | - | ||||||||||||
177 | Q_ASSERT(buffer->m_manager == nullptr); | - | ||||||||||||
178 | Q_ASSERT(!m_buffers.contains(buffer->m_format)); | - | ||||||||||||
179 | buffer->m_manager = this; | - | ||||||||||||
180 | m_buffers.insert(buffer->m_format, buffer.toWeakRef()); | - | ||||||||||||
181 | } executed 67 times by 5 tests: end of block Executed by:
| 67 | ||||||||||||
182 | - | |||||||||||||
183 | uint qHash(const QSGDepthStencilBuffer::Format &format) | - | ||||||||||||
184 | { | - | ||||||||||||
185 | return qHash(qMakePair(format.size.width(), format.size.height())) executed 172 times by 5 tests: return qHash(qMakePair(format.size.width(), format.size.height())) ^ (uint(format.samples) << 12) ^ (uint(format.attachments) << 28); Executed by:
| 172 | ||||||||||||
186 | ^ (uint(format.samples) << 12) ^ (uint(format.attachments) << 28); executed 172 times by 5 tests: return qHash(qMakePair(format.size.width(), format.size.height())) ^ (uint(format.samples) << 12) ^ (uint(format.attachments) << 28); Executed by:
| 172 | ||||||||||||
187 | } | - | ||||||||||||
188 | - | |||||||||||||
189 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |