1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt3D 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 "graphicshelperes3_2_p.h"
41#include <QOpenGLExtraFunctions>
42#include <Qt3DRender/qrendertargetoutput.h>
43#include <private/attachmentpack_p.h>
44
45QT_BEGIN_NAMESPACE
46
47#ifndef GL_DRAW_FRAMEBUFFER
48#define GL_DRAW_FRAMEBUFFER 0x8CA9
49#endif
50
51#ifndef GL_DEPTH_STENCIL_ATTACHMENT
52#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
53#endif
54
55#ifndef GL_PATCH_VERTICES
56#define GL_PATCH_VERTICES 36466
57#endif
58
59#ifndef GL_IMAGE_BUFFER
60#define GL_IMAGE_BUFFER 0x9051
61#endif
62#ifndef GL_IMAGE_CUBE_MAP_ARRAY
63#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
64#endif
65#ifndef GL_INT_IMAGE_BUFFER
66#define GL_INT_IMAGE_BUFFER 0x905C
67#endif
68#ifndef GL_INT_IMAGE_CUBE_MAP_ARRAY
69#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
70#endif
71#ifndef GL_UNSIGNED_INT_IMAGE_BUFFER
72#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
73#endif
74#ifndef GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY
75#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
76#endif
77
78namespace Qt3DRender {
79namespace Render {
80namespace OpenGL {
81
82GraphicsHelperES3_2::GraphicsHelperES3_2()
83{
84}
85
86GraphicsHelperES3_2::~GraphicsHelperES3_2()
87{
88}
89
90bool GraphicsHelperES3_2::supportsFeature(GraphicsHelperInterface::Feature feature) const
91{
92 switch (feature) {
93 case GraphicsHelperInterface::Tessellation:
94 return true;
95 default:
96 break;
97 }
98 return GraphicsHelperES3_1::supportsFeature(feature);
99}
100
101bool GraphicsHelperES3_2::frameBufferNeedsRenderBuffer(const Attachment &attachment)
102{
103 Q_UNUSED(attachment);
104 // This is first ES version where we have glFramebufferTexture, so
105 // attaching a D24S8 texture to the combined depth-stencil attachment point
106 // should work.
107 return false;
108}
109
110void GraphicsHelperES3_2::bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment)
111{
112 GLenum attr = GL_COLOR_ATTACHMENT0;
113
114 if (attachment.m_point <= QRenderTargetOutput::Color15)
115 attr = GL_COLOR_ATTACHMENT0 + attachment.m_point;
116 else if (attachment.m_point == QRenderTargetOutput::Depth)
117 attr = GL_DEPTH_ATTACHMENT;
118 else if (attachment.m_point == QRenderTargetOutput::Stencil)
119 attr = GL_STENCIL_ATTACHMENT;
120 else if (attachment.m_point == QRenderTargetOutput::DepthStencil)
121 attr = GL_DEPTH_STENCIL_ATTACHMENT;
122 else
123 qCritical() << "Unsupported FBO attachment OpenGL ES 3.2";
124
125 const QOpenGLTexture::Target target = texture->target();
126
127 texture->bind();
128 if (target == QOpenGLTexture::TargetCubeMap && attachment.m_face != QAbstractTexture::AllFaces)
129 m_funcs->glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment: attr, textarget: attachment.m_face, texture: texture->textureId(), level: attachment.m_mipLevel);
130 else
131 m_extraFuncs->glFramebufferTexture(GL_DRAW_FRAMEBUFFER, attachment: attr, texture: texture->textureId(), level: attachment.m_mipLevel);
132 texture->release();
133}
134
135void GraphicsHelperES3_2::setVerticesPerPatch(GLint verticesPerPatch)
136{
137 m_extraFuncs->glPatchParameteri(GL_PATCH_VERTICES, value: verticesPerPatch);
138}
139
140void GraphicsHelperES3_2::drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex, GLint baseInstance)
141{
142 if (baseInstance != 0)
143 qWarning() << "glDrawElementsInstancedBaseVertexBaseInstance is not supported with OpenGL ES 2";
144
145 m_extraFuncs->glDrawElementsInstancedBaseVertex(mode: primitiveType,
146 count: primitiveCount,
147 type: indexType,
148 indices,
149 instancecount: instances,
150 basevertex: baseVertex);
151}
152
153UniformType GraphicsHelperES3_2::uniformTypeFromGLType(GLenum glType)
154{
155 switch (glType) {
156 case GL_IMAGE_BUFFER:
157 case GL_IMAGE_CUBE_MAP_ARRAY:
158 case GL_INT_IMAGE_BUFFER:
159 case GL_INT_IMAGE_CUBE_MAP_ARRAY:
160 case GL_UNSIGNED_INT_IMAGE_BUFFER:
161 case GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:
162 return UniformType::Image;
163
164 default:
165 return GraphicsHelperES3_1::uniformTypeFromGLType(glType);
166 }
167}
168
169uint GraphicsHelperES3_2::uniformByteSize(const ShaderUniform &description)
170{
171 uint rawByteSize = 0;
172
173 switch (description.m_type) {
174 case GL_IMAGE_BUFFER:
175 case GL_IMAGE_CUBE_MAP_ARRAY:
176 case GL_INT_IMAGE_BUFFER:
177 case GL_INT_IMAGE_CUBE_MAP_ARRAY:
178 case GL_UNSIGNED_INT_IMAGE_BUFFER:
179 case GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY:
180 rawByteSize = 4;
181 break;
182
183 default:
184 rawByteSize = GraphicsHelperES3_1::uniformByteSize(description);
185 break;
186 }
187
188 return rawByteSize;
189}
190
191} // namespace OpenGL
192} // namespace Render
193} // namespace Qt3DRender
194
195QT_END_NAMESPACE
196

source code of qt3d/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_2.cpp